Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 23427
  • Last Modified:

How do i draw a circle in C#

hii,

 how do i draw a circle in C# ??
0
madmare
Asked:
madmare
1 Solution
 
Pete LongTechnical ConsultantCommented:
Hi madmare,
How to draw a Circle on a Window?
http://www.c-sharpcorner.com/1/draw_1.asp

PeteL
0
 
PerryDKCommented:
Write an even handler for the paint event of the form.  Then draw an elipse using the width and height equal to each other.  This will be the radius.

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
      int centerX = 50;
      int centerY = 50;
      int radius = 25;

      e.Graphics.DrawEllipse(Pens.CornflowerBlue, centerX, centerY, radius, radius);
}
0
 
cyberdevil67Commented:
Madmare,

There are a few ways you can do this, the first is to use the OnPain method as described by PerryDK. The second is to use the control in this case the form, and get the Graphics Handler with

Graphics g = form1.CreateGraphics();

And then you can use the g.DrawEllipse method.
0
 
Mohammad Aamir QureshiCommented:
Well
protected void Form1_Paint (object sender, System.WinForms.PaintEventArgs e)
{
     Graphics g = e.Graphics ;
     Pen mypen = new Pen( Color.Red, 5 ) ;
     SolidBrush mybrush = new SolidBrush ( Color.Blue ) ;
     g.FillEllipse( mybrush, 20, 200, 150, 100);
     g.DrawEllipse( mypen, 20, 200, 150, 100);

}

Check this
0
 
caner_elciCommented:
Also, don't forget to add Form1_Paint event handler to Form1's Paint event... I felt like I have to tell you this.. You can do that in form designer, using events tab of properties panel.. Or you can add it manually, like:

this.Paint += new EventHandler(Form1_Paint);

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now