private void pictureBox1_Paint(object sender, PaintEventArgs e) { Pen pen = GetPen(); Graphics mainGraphics = Graphics.FromImage(canvas); Graphics blockGraphics = Graphics.FromImage(blockCanvas); if (!isDraw) // Рисовать курсор { blockGraphics.Clear(Color.White); switch (mode) { case Mode.Pencil: case Mode.Eraser: { blockGraphics.DrawEllipse(new Pen(new SolidBrush(Color.Black)), new Rectangle(X - (int)(Convert.ToInt32(Convert.ToDouble(BrushSize.Value) * ScaleFactor) / 2), Y - (int)(Convert.ToInt32(Convert.ToDouble(BrushSize.Value) * ScaleFactor) / 2), (int)Convert.ToInt32(Convert.ToDouble(BrushSize.Value) * ScaleFactor), (int)Convert.ToInt32(Convert.ToDouble(BrushSize.Value) * ScaleFactor))); break; } case Mode.Rectangle: case Mode.Ellipse: case Mode.Triangle: case Mode.Line: case Mode.Bucket: { blockGraphics.DrawLine(new Pen(new SolidBrush(Color.Black)), new Point(X - 4, Y), new Point(X + 4, Y)); blockGraphics.DrawLine(new Pen(new SolidBrush(Color.Black)), new Point(X, Y - 4), new Point(X, Y + 4)); break; } } if (mode != Mode.None) { blockGraphics.DrawImage(canvas, 0, 0); pictureBox1.Image = blockCanvas; } } else // Рисвать сами объекты { switch (mode) { case Mode.Pencil: { mainGraphics.DrawLine(pen, endX, endY, X, Y); pictureBox1.Image = canvas; break; } case Mode.Line: { blockGraphics.Clear(Color.White); blockGraphics.DrawImage(canvas, 0, 0); blockGraphics.DrawLine(pen, endClickX, endClickY, X, Y); pictureBox1.Image = blockCanvas; break; } case Mode.Eraser: { mainGraphics.DrawLine(GetPen(Color.White), endX, endY, X, Y); pictureBox1.Image = canvas; break; } case Mode.Rectangle: { blockGraphics.Clear(Color.White); blockGraphics.DrawImage(canvas, 0, 0); int x, y; x = endClickX; y = endClickY; if (x > X) { x = X; } if (y > Y) { y = Y; } blockGraphics.DrawRectangle(pen, x, y, Math.Abs(X - endClickX), Math.Abs(Y - endClickY)); pictureBox1.Image = blockCanvas; break; } case Mode.Ellipse: { blockGraphics.Clear(Color.White); blockGraphics.DrawImage(canvas, 0, 0); blockGraphics.DrawEllipse(pen, endClickX, endClickY, X - endClickX, Y - endClickY); pictureBox1.Image = blockCanvas; break; } case Mode.Triangle: { blockGraphics.Clear(Color.White); blockGraphics.DrawImage(canvas, 0, 0); Point a = new Point((X + endClickX) / 2, endClickY); Point b = new Point(endClickX, Y); Point c = new Point(X, Y); blockGraphics.DrawPolygon(pen, new Point[] { a, b, c }); pictureBox1.Image = blockCanvas; break; } } } endX = X; endY = Y; }
public void DrawShapeGI(Graphics gI, int X, int Y, float width, float height) { gI.DrawRectangle(pen, (float)(Math.Min(fX, X) / scale), (float)(Math.Min(fY, Y) / scale), width, height); }
public override void Clear(Graphics g) { g.DrawRectangle(whitePen, boundingRect); }
public override void Draw(Graphics g) { g.DrawRectangle(pen, boundingRect); }
private void DravFigure(MouseEventArgs e) { if (!Transparent) { if (rectangle) { if (e.X < x && e.Y < y) { g.FillRectangle(myBrush, e.X, e.Y, x - e.X, y - e.Y); } else if (e.X < x) { g.FillRectangle(myBrush, e.X, y, x - e.X, e.Y - y); } else if (e.Y < y) { g.FillRectangle(myBrush, x, e.Y, e.X - x, y - e.Y); } else { g.FillRectangle(myBrush, x, y, e.X - x, e.Y - y); } } else { if (e.X < x && e.Y < y) { g.FillEllipse(myBrush, new Rectangle(e.X, e.Y, x - e.X, y - e.Y)); } else if (e.X < x) { g.FillEllipse(myBrush, new Rectangle(e.X, y, x - e.X, e.Y - y)); } else if (e.Y < y) { g.FillEllipse(myBrush, new Rectangle(x, e.Y, e.X - x, y - e.Y)); } else { g.FillEllipse(myBrush, new Rectangle(x, y, e.X - x, e.Y - y)); } } } if (rectangle) { if (e.X < x && e.Y < y) { g.DrawRectangle(pen, e.X, e.Y, x - e.X, y - e.Y); } else if (e.X < x) { g.DrawRectangle(pen, e.X, y, x - e.X, e.Y - y); } else if (e.Y < y) { g.DrawRectangle(pen, x, e.Y, e.X - x, y - e.Y); } else { g.DrawRectangle(pen, x, y, e.X - x, e.Y - y); } } else { if (e.X < x && e.Y < y) { g.DrawEllipse(pen, new Rectangle(e.X, e.Y, x - e.X, y - e.Y)); } else if (e.X < x) { g.DrawEllipse(pen, new Rectangle(e.X, y, x - e.X, e.Y - y)); } else if (e.Y < y) { g.DrawEllipse(pen, new Rectangle(x, e.Y, e.X - x, y - e.Y)); } else { g.DrawEllipse(pen, new Rectangle(x, y, e.X - x, e.Y - y)); } } }
public void DrawRegionGroup(int[] A, int count) { graphic.DrawRectangle(penRegion, PMinGroup(A, count).X, PMinGroup(A, count).Y, PMaxGroup(A, count).X - PMinGroup(A, count).X, PMaxGroup(A, count).Y - PMinGroup(A, count).Y); }