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; }