• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 24005
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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