Drawing circles with System.Drawing

后端 未结 8 1080
醉酒成梦
醉酒成梦 2021-01-03 22:56

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

 case \"Rectangle\":
               if (tempDraw != null)
                {
             


        
相关标签:
8条回答
  • 2021-01-03 23:41

    There is no DrawCircle method; use DrawEllipse instead. I have a static class with handy graphics extension methods. The following ones draw and fill circles. They are wrappers around DrawEllipse and FillEllipse:

    public static class GraphicsExtensions
    {
        public static void DrawCircle(this Graphics g, Pen pen,
                                      float centerX, float centerY, float radius)
        {
            g.DrawEllipse(pen, centerX - radius, centerY - radius,
                          radius + radius, radius + radius);
        }
    
        public static void FillCircle(this Graphics g, Brush brush,
                                      float centerX, float centerY, float radius)
        {
            g.FillEllipse(brush, centerX - radius, centerY - radius,
                          radius + radius, radius + radius);
        }
    }
    

    You can call them like this:

    g.FillCircle(myBrush, centerX, centerY, radius);
    g.DrawCircle(myPen, centerX, centerY, radius);
    
    0 讨论(0)
  • 2021-01-03 23:48

    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);
        }
     }
    
    0 讨论(0)
提交回复
热议问题