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); } }
/// <summary> /// drawing in canvas /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void PcanvasMouseClick(object sender, MouseEventArgs e) { if (k == 1) { x = e.X; y = e.Y; dX = e.X - cX; dY = e.Y - cY; if (shape == "line") { g.DrawLine(new Pen(color, p.Width), cX, cY, e.X, e.Y); } if (shape == "circle") { g.DrawEllipse(new Pen(color, p.Width), cX, cY, dX, dY); } if (shape == "rectangle") { shapes = shapeFactory.getShape("RECTANGLE"); shapes.SetParam(cX, cY, dX, dY, color); g.DrawRectangle(new Pen(color, p.Width), cX, cY, dX, dY); } if (shape == "triangle") { Pen p = new Pen(color, 40); Point[] pnt = new Point[3]; pnt[0].X = cX; pnt[0].Y = cY - trackBar1.Value; pnt[1].X = cX + trackBar1.Value; pnt[1].Y = cY + trackBar1.Value; pnt[2].X = cX - trackBar1.Value; pnt[2].Y = cY + trackBar1.Value; g.DrawPolygon(p, pnt); } if (shape == "polygon") { Point[] pnt = new Point[6]; System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(color); pnt[0].X = cX; pnt[0].Y = cY; pnt[1].X = cX + trackBar1.Value + 40; pnt[1].Y = cY; pnt[2].X = cX + trackBar1.Value + 40 + (trackBar1.Value + 40 / 2); pnt[2].Y = cY + trackBar1.Value + 40; pnt[3].X = cX - (trackBar1.Value + 40 / 2); pnt[3].Y = cY + trackBar1.Value + 40; pnt[4].X = cX; pnt[4].Y = cY; g.FillPolygon(myBrush, pnt); } } }