private void plMain_MouseUp(object sender, MouseEventArgs e) { if (statusPaint.isNotDrawing == false) { if (isShape == IsShape.Curve || isShape == IsShape.Polygon) { } else { if (isShape == IsShape.Pen && statusPaint.isStart == true) { Shape temp = new lPen(); temp.myPen = new Pen(myColor, width); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); this.lShape[this.lShape.Count - 1].p1 = this.lShape[this.lShape.Count - 2].p2; this.lShape[this.lShape.Count - 1].p2 = e.Location; this.plMain.Refresh(); } else if (statusPaint.isStart == true) { this.lShape[this.lShape.Count - 1].p2 = e.Location; this.plMain.Refresh(); } statusPaint.isStart = false; this.Cursor = Cursors.Default; } } else { if (statusPaint.isMouseDown) { if (statusPaint.isSelectedOneShape) { pLast = e.Location; if (statusPaint.isZoom) { ZoomShape(indexShapeSelected, pFirst, pLast); } else { MoveShape(indexShapeSelected, pFirst, pLast); } plMain.Refresh(); statusPaint.isSelectedOneShape = false; statusPaint.isMouseDown = false; statusPaint.isStart = false; statusPaint.isZoom = false; } } } }
private void plMain_MouseMove(object sender, MouseEventArgs e) { if (statusPaint.isNotDrawing == false) { if (isShape == IsShape.Pen && statusPaint.isStart == true) // để vẽ đường nét tự do, { Shape temp = new lPen(); // tạo 1 hình tạm để fix lỗi khi list hình rỗng temp.myPen = new Pen(myColor, width); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); this.lShape[this.lShape.Count - 1].p1 = this.lShape[this.lShape.Count - 2].p2; this.lShape[this.lShape.Count - 1].p2 = e.Location; this.plMain.Refresh(); } else if (statusPaint.isDrawPolygon == true) { if (isShape == IsShape.Polygon) { Polygon temp = lShape[lShape.Count - 1] as Polygon; if (temp != null) { temp.lPoint[temp.lPoint.Count - 1] = e.Location; } } else { Curve temp = lShape[lShape.Count - 1] as Curve; if (temp != null) { temp.lPoint[temp.lPoint.Count - 1] = e.Location; } } this.plMain.Refresh(); } else if (statusPaint.isStart == true) { this.lShape[this.lShape.Count - 1].p2 = e.Location; this.plMain.Refresh(); } } else { if (statusPaint.isMouseDown) { if (statusPaint.isSelectedOneShape && indexShapeSelected != -1 && indexShapeSelected < lShape.Count) { pLast = e.Location; if (statusPaint.isZoom) { ZoomShape(indexShapeSelected, pFirst, pLast); this.plMain.Refresh(); } else { MoveShape(indexShapeSelected, pFirst, pLast); plMain.Refresh(); } } } } }
private void plMain_MouseDown(object sender, MouseEventArgs e) { if (statusPaint.isNotDrawing == false) { switch (isShape) { case IsShape.Line: { Shape temp = new Line(); setPropertiesShape(temp); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); statusPaint.isStart = true; break; } case IsShape.Rectangle: { Shape temp = new Rectangle(); setPropertiesShape(temp); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); statusPaint.isStart = true; break; } case IsShape.Ellipes: { Shape temp = new Ellipse(); setPropertiesShape(temp); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); statusPaint.isStart = true; break; } case IsShape.Circle: { Shape temp = new Circle(); setPropertiesShape(temp); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); statusPaint.isStart = true; break; } case IsShape.Square: { Shape temp = new Square(); setPropertiesShape(temp); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); statusPaint.isStart = true; break; } case IsShape.Pen: { Shape temp = new lPen(); setPropertiesShape(temp); temp.p1 = e.Location; temp.p2 = e.Location; lShape.Add(temp); statusPaint.isStart = true; break; } case IsShape.Polygon: { if (statusPaint.isDrawPolygon == false) { statusPaint.isDrawPolygon = true; Shape temp = new Polygon(); setPropertiesShape(temp); temp.lPoint.Add(e.Location); temp.lPoint.Add(e.Location); lShape.Add(temp); statusPaint.isStart = true; } else { Polygon temp = lShape[lShape.Count - 1] as Polygon; temp.lPoint[temp.lPoint.Count - 1] = e.Location; temp.lPoint.Add(e.Location); } break; } case IsShape.Curve: { if (statusPaint.isDrawPolygon == false) { Shape temp = new Curve(); setPropertiesShape(temp); temp.lPoint.Add(e.Location); temp.lPoint.Add(e.Location); lShape.Add(temp); statusPaint.isStart = true; statusPaint.isDrawPolygon = true; } else { Curve temp = lShape[lShape.Count - 1] as Curve; temp.lPoint[temp.lPoint.Count - 1] = e.Location; temp.lPoint.Add(e.Location); } break; } default: break; } } else { plMain.Cursor = Cursors.Default; statusPaint.isStart = true; if (statusPaint.isSelectedOneShape) { statusPaint.isMouseDown = true; pFirst = e.Location; pastDistanceX = 0; pastDistanceY = 0; if (pLast != null && indexShapeSelected != -1 && lShape.Count > 0 && indexShapeSelected < lShape.Count && lShape[indexShapeSelected].isPointOfControl(pLast) == true) { plMain.Cursor = Cursors.SizeNESW; statusPaint.isZoom = true; } } else { if (pressControl) { plMain.Cursor = Cursors.SizeAll; lShape.ForEach(shape => { if (shape.isHit(e.Location) && shape.isSelected == false) { shape.isSelected = true; } }); this.plMain.Refresh(); statusPaint.isSelectedOneShape = false; } else { plMain.Cursor = Cursors.Default; statusPaint.isSelectedOneShape = false; lShape.ForEach(shape => { shape.isSelected = false; }); selectedShape(e.Location); this.plMain.Refresh(); } } } }