private void customPanel1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (isDrawing && !isEditStatus) { switch (selectedType.val) { case 0: //直线 case 1: //矩形 case 3: //园 endPoint = new Point(e.X, e.Y); break; case 2: //多边形 pointList.Add(new Point(e.X, e.Y)); break; default: break; } } if (isEditStatus) { if (selectedLine) { GraphicHelper.moveLine(ref startPoint, ref endPoint, ref mouseDownPoint, new Point(e.X, e.Y)); } else if (selectedStartPoint) { startPoint = new Point(e.X, e.Y); } else if (selectedEndPoint) { endPoint = new Point(e.X, e.Y); } else if (selectedRect) { GraphicHelper.moveRect(ref startPoint, ref endPoint, ref mouseDownPoint, new Point(e.X, e.Y)); } else if (selectedVertex) { GraphicHelper.modifyVertex(ref pointList, ref mouseDownPoint, new Point(e.X, e.Y)); } else if (selectedPolygon) { GraphicHelper.movePolygon(ref pointList, ref mouseDownPoint, new Point(e.X, e.Y)); } } } }
private void customPanel1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (isDrawing && !isEditStatus) { switch (selectedType.val) { case 0: //直线 case 1: //矩形 case 3: //园 startPoint = new Point(e.X, e.Y); break; case 2: pointList.Add(new Point(e.X, e.Y)); break; default: break; } } if (isEditStatus) { resetOperation(); mouseDownPoint = new Point(e.X, e.Y); switch (selectedType.val) { case 0: //直线 if (GraphicHelper.GetPointIsInLine(mouseDownPoint, startPoint, endPoint, 1)) { selectedLine = true; //MessageBox.Show("选中线了"); } else if (GraphicHelper.IsThisPoint(mouseDownPoint, startPoint, 1)) { selectedStartPoint = true; } else if (GraphicHelper.IsThisPoint(mouseDownPoint, endPoint, 1)) { selectedEndPoint = true; } break; case 1: //矩形 pointList.Add(startPoint); pointList.Add(new Point(endPoint.X, startPoint.Y)); pointList.Add(endPoint); pointList.Add(new Point(startPoint.X, endPoint.Y)); if (GraphicHelper.IsPointInPolygon(mouseDownPoint, pointList.ToArray())) { selectedRect = true; //MessageBox.Show("选中面了"); pointList.Clear(); } break; case 3: //园 break; case 2: //多边形 if (GraphicHelper.IsPointInPolygon(mouseDownPoint, pointList.ToArray())) { selectedPolygon = true; //MessageBox.Show("选中面了"); } else if (GraphicHelper.IsGraphVertex(ref pointList, mouseDownPoint)) { selectedVertex = true; //MessageBox.Show("选中顶点了"); } break; default: break; } } } }