コード例 #1
0
 private void MyRectangle(Point startP, Point endP)
 {
     Apis.MoveToEx(hdc, startP.X, startP.Y, IntPtr.Zero);
     //Apis.LineTo(hdc, pt2.X, pt2.Y);
     SketchpadPosition = new Rectangle(startP.X, startP.Y, endP.X, endP.Y);
     Apis.Rectangle(hdc, SketchpadPosition.X, SketchpadPosition.Y, SketchpadPosition.Width, SketchpadPosition.Height);
 }
コード例 #2
0
        /// <summary>
        /// "鼠标按下"事件处理方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (!m_isdown)
            {
                m_isdown      = true;
                StartLocation = new Point(e.X, e.Y);
                EndLocation   = new Point(e.X, e.Y);
                hdc           = Apis.GetDC(this.panel1.Handle);
                Apis.SetROP2(hdc, R2.R2_NOTCOPYPEN);
            }
            else
            {
                MyRectangle(StartLocation, EndLocation);
                MyRectangle(StartLocation, new Point(e.X, e.Y));
                Apis.ReleaseDC(this.panel1.Handle, hdc);
            }

            #region  标按下网格处理代码

            bool isclick = false;
            if (e.Button == MouseButtons.Left)
            {
                for (int i = 0; i < Grids.Count; i++)
                {
                    Point mouseLocation = e.Location;

                    if ((Grids[i].Type == -1 || Grids[i].Type == 2 || Grids[i].Type == 1) && Grids[i].Rect.Contains(mouseLocation))
                    {
                        for (int k = 0; k < Grids.Count; k++)
                        {
                            bool isSelected = SelectedRowAndCol(Grids[i].Type, Grids[i].DridLocation, Grids[k].DridLocation);
                            if (isSelected)
                            {
                                Grids[k].IsSelected = true;
                                isclick             = true;
                                panel1.Invalidate(Grids[k].Rect);
                            }
                            else
                            {
                                if (Grids[k].IsSelected)
                                {
                                    Grids[k].IsSelected = false;
                                    panel1.Invalidate(Grids[k].Rect);
                                }
                            }
                        }
                    }

                    if (Grids[i].Type == 0)
                    {
                        if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                        {
                            if (Grids[i].Rect.Contains(mouseLocation))
                            {
                                Grids[i].IsSelected = true;
                                panel1.Invalidate(Grids[i].Rect);
                            }
                        }
                        else
                        {
                            if (Grids[i].Rect.Contains(mouseLocation))
                            {
                                Grids[i].IsSelected = true;
                                isclick             = false;
                                panel1.Invalidate(Grids[i].Rect);
                            }
                            else
                            {
                                if (isclick)
                                {
                                    continue;
                                }
                                if (Grids[i].IsSelected)
                                {
                                    Grids[i].IsSelected = false;
                                    panel1.Invalidate(Grids[i].Rect);
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }