private void Picture_MouseUp(object sender, MouseEventArgs e) { if (IsMoved == true) { if (linePanel.BackColor == Color.Green) { g.DrawLine(new Pen(CurrentColor, PenWidth), firstP, secondP); } if (circlePanel.BackColor == Color.Green) { if (menu_fill.BackColor == SystemColors.Control) { g.DrawEllipse(new Pen(CurrentColor, PenWidth), leftX, leftY, width, height); } else { g.FillEllipse(new SolidBrush(CurrentColor), leftX, leftY, width, height); } } if (polygonPanel.BackColor == Color.Green && AmountOfSides > 2) { if (menu_fill.BackColor == SystemColors.Control) { g.DrawPolygon(new Pen(CurrentColor, PenWidth), points.ToArray()); } else { g.FillPolygon(new SolidBrush(CurrentColor), points.ToArray()); } } if (menu_additionally_rect.BackColor == Color.Green || menu_additionally_square.BackColor == Color.Green) { if (menu_fill.BackColor == SystemColors.Control) { g.DrawRectangle(new Pen(CurrentColor, PenWidth), firstP.X, firstP.Y, width, height); } else { g.FillRectangle(new SolidBrush(CurrentColor), firstP.X, firstP.Y, width, height); } } if (menu_additionally_circle.BackColor == Color.Green) { if (menu_fill.BackColor == SystemColors.Control) { g.DrawEllipse(new Pen(CurrentColor, PenWidth), new Rectangle(leftX, leftY, width, height)); } else { g.FillEllipse(new SolidBrush(CurrentColor), new Rectangle(leftX, leftY, width, height)); } } picture.Invalidate(); IsMoved = false; } }
private void panelPaint_MouseClick(object sender, MouseEventArgs e) { if (active.Equals("pen")) { g.DrawLine(pen, new Point(x, y), e.Location); x = e.X; y = e.Y; } else if (active.Equals("eraser")) { System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White); g.FillRectangle(myBrush, e.X, e.Y, 24, 24); } else if (active.Equals("rectangle")) { shapes = shapeFactory.getShape("RECTANGLE"); shapes.SetParam(e.X - size / 2, e.Y - size / 2, size, size, mainColor); SolidBrush myBrush = new SolidBrush(mainColor); g.FillRectangle(myBrush, e.X - size / 2, e.Y - size / 2, size, size); } else if (active.Equals("triangle")) { System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(mainColor); Point[] pnt = new Point[3]; pnt[0].X = e.X; pnt[0].Y = e.Y - size; pnt[1].X = e.X + size; pnt[1].Y = e.Y + size; pnt[2].X = e.X - size; pnt[2].Y = e.Y + size; g.FillPolygon(myBrush, pnt); } else if (active.Equals("circle")) { System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(mainColor); g.FillEllipse(myBrush, e.X - size / 2, e.Y - size / 2, size, size); } else if (active.Equals("polygon")) { Pen myPen = new Pen(mainColor); Point[] pnt = new Point[5]; pnt[0].X = mouseX; pnt[0].Y = mouseY; pnt[1].X = mouseX + size; pnt[1].Y = mouseY; pnt[2].X = mouseX + size + (size / 2); pnt[2].Y = mouseY + size; pnt[3].X = mouseX - (size / 2); pnt[3].Y = mouseY + size; pnt[4].X = mouseX; pnt[4].Y = mouseY; g.DrawPolygon(myPen, pnt); } }
private void pictureBox_MouseMove(Object sender, MouseEventArgs e) { if (dragNdrop) { this.pictureBox.Cursor = Cursors.SizeAll; } else { this.pictureBox.Cursor = Cursors.Cross; } if (drawMouse == false) { goto jump;// k phải đang dí chuột thì nhảy tới jump } x1 = e.X; y1 = e.Y; //g.Clear(Color.White); drawing = new Bitmap(drawingList.ElementAt(drawingList.currentIndex)); //pictureBox.Image = drawingList.Last(); g = Graphics.FromImage(drawing); //chọn pen Pen pen = choosePen(e); if (currentFillItem != fillType.NoFill) //vẽ phía trong { Brush brush = chooseBrush(e); brushShape(brush, x, y, x1, y1); } //Vẽ đường ngoài switch (currentItem) { case item.Select: { if (dragNdrop) { Console.WriteLine("Selecting"); //this.pictureBox.Cursor = Cursors.SizeAll; //tạo nét đứt xung quanh //dashDraw(new Rectangle(selectedArea.X+ (x1 - x), selectedArea.Y + (y1 - y),selectedArea.Width-1,selectedArea.Height)); //xoá hình select trên hình hiện tại Bitmap nullImage = new Bitmap(selectImage); Graphics nullGraphics = Graphics.FromImage(nullImage); nullGraphics.Clear(Color.White); g.DrawImageUnscaled(nullImage, selectedArea.X, selectedArea.Y); //vẽ hình select lên vị trí mới g.DrawImageUnscaled(selectImage, selectedArea.X + (x1 - x), selectedArea.Y + (y1 - y)); //pictureBox.Image = drawing; } else { dashDraw(Rectangle1(x, y, x1, y1)); } break; } case item.Pen: { //Pen pen = pen_properties(currentColor, currentWidth); //g.DrawLine(p, x, y, x1, y1); //x = x1; y = y1; pointList.Add(new Point(x1, y1)); try { g.DrawLines(pen, pointList.ToArray()); //g.DrawCurve(pen, pointList.ToArray()); ////g.DrawBeziers(pen, pointList.ToArray()); } catch (Exception ex) { } break; } case item.Eraser: { SolidBrush brush = new SolidBrush(Color.White); rectangleList.Add(new Rectangle(new Point(x1, y1), new Size(currentWidth, currentWidth))); g.FillRectangles(brush, rectangleList.ToArray()); break; } case item.Line: { g.DrawLine(pen, new Point(x, y), new Point(x1, y1)); //pictureBox1.CreateGraphics().DrawImageUnscaled(drawing, 0, 0); break; } case item.Oval: { g.DrawEllipse(pen, x, y, x1 - x, y1 - y); break; } case item.Rectangle: { g.DrawRectangle(pen, Rectangle1(x, y, x1, y1)); break; } case item.TriCan: { Point[] pList = new Point[3]; pList[0] = new Point((x + x1) / 2, y); pList[1] = new Point(x, y1); pList[2] = new Point(x1, y1); g.DrawPolygon(pen, pList); break; } case item.TriVuong: { Point[] pList = new Point[3]; pList[0] = new Point(x, y); pList[1] = new Point(x, y1); pList[2] = new Point(x1, y1); g.DrawPolygon(pen, pList); break; } case item.Diamond: { Point[] pList = new Point[4]; pList[0] = new Point((x + x1) / 2, y); pList[1] = new Point(x, (y + y1) / 2); pList[2] = new Point((x + x1) / 2, y1); pList[3] = new Point(x1, (y + y1) / 2); g.DrawPolygon(pen, pList); break; } } pictureBox.Image = drawing; // hiển thị jump :; }