Drawing circles with System.Drawing

后端 未结 8 1079
醉酒成梦
醉酒成梦 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:22

    You should use DrawEllipse:

    //
    // Summary:
    //     Draws an ellipse defined by a bounding rectangle specified by coordinates
    //     for the upper-left corner of the rectangle, a height, and a width.
    //
    // Parameters:
    //   pen:
    //     System.Drawing.Pen that determines the color, width,
    //      and style of the ellipse.
    //
    //   x:
    //     The x-coordinate of the upper-left corner of the bounding rectangle that
    //     defines the ellipse.
    //
    //   y:
    //     The y-coordinate of the upper-left corner of the bounding rectangle that
    //     defines the ellipse.
    //
    //   width:
    //     Width of the bounding rectangle that defines the ellipse.
    //
    //   height:
    //     Height of the bounding rectangle that defines the ellipse.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     pen is null.
    public void DrawEllipse(Pen pen, int x, int y, int width, int height);
    
    0 讨论(0)
  • 2021-01-03 23:23

    if you want to draw circle on button then this code might be use full. else if you want to draw a circle on other control just change the name of control and also event. like here event button is called. if you want to draw this circle in group box call the Groupbox event. regards

        public Form1()
        {
            InitializeComponent();
    
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            this.button1.Location = new Point(108, 12);
           // this.Paint += new PaintEventHandler(Form1_Paint);
            this.button1.Paint += new PaintEventHandler(button1_Paint);
        }
        void button1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = this.button1.CreateGraphics();
            Pen pen = new Pen(Color.Red);
            g.DrawEllipse(pen, 10, 10, 20, 20);
    
        }
    
    
    
    
    
    }
    
    0 讨论(0)
  • 2021-01-03 23:23
    PictureBox circle = new PictureBox();
    circle.Paint += new PaintEventHandler(circle_Paint);        
    
    void circle_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawEllipse(Pens.Red, 0, 0, 30, 30);
            }
    
    0 讨论(0)
  • 2021-01-03 23:24
         private void DrawEllipseRectangle(PaintEventArgs e)
            {
                Pen p = new Pen(Color.Black, 3);
                Rectangle r = new Rectangle(100, 100, 100, 100);
                e.Graphics.DrawEllipse(p, r);
            }
         private void Form1_Paint(object sender, PaintEventArgs e)
            {
                DrawEllipseRectangle(e);
            }
    
    0 讨论(0)
  • 2021-01-03 23:32

    You'll need to use DrawEllipse if you want to draw a circle using GDI+.

    An example is here: http://www.websupergoo.com/helpig6net/source/3-examples/9-drawgdi.htm

    0 讨论(0)
  • 2021-01-03 23:33

    Try the DrawEllipse method instead.

    0 讨论(0)
提交回复
热议问题