Drawing circles with System.Drawing

2019-02-12 02:02发布

I have this code that draws a Rectangle ( Im trying to remake the MS Paint )

 case "Rectangle":
               if (tempDraw != null)
                {
                    tempDraw = (Bitmap)snapshot.Clone();
                    Graphics g = Graphics.FromImage(tempDraw);
                    Pen myPen = new Pen(foreColor, lineWidth);
                    g.DrawRectangle(myPen, x1, y1, x2-x1, y2-y1);
                    myPen.Dispose();
                    e.Graphics.DrawImageUnscaled(tempDraw, 0, 0);
                    g.Dispose();
                }

But what if I want to draw a circle, what will change?

g.DrawRectangle(myPen, x1, y1, x2-x1, y2-y1);

标签: c# drawing
7条回答
放我归山
2楼-- · 2019-02-12 02:55

With this code you can easily draw a circle... C# is great and easy my friend

public partial class Form1 : Form
{


public Form1()
    {
        InitializeComponent();
    }

  private void button1_Click(object sender, EventArgs e)
    {
        Graphics myGraphics = base.CreateGraphics();
        Pen myPen = new Pen(Color.Red);
        SolidBrush mySolidBrush = new SolidBrush(Color.Red);
        myGraphics.DrawEllipse(myPen, 50, 50, 150, 150);
    }
 }
查看更多
登录 后发表回答