How do i draw a circle in C#

Posted on 2005-04-12
Last Modified: 2008-01-09

 how do i draw a circle in C# ??
Question by:madmare
    LVL 57

    Expert Comment

    by:Pete Long
    Hi madmare,
    How to draw a Circle on a Window?

    LVL 4

    Expert Comment

    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);
    LVL 9

    Expert Comment


    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.
    LVL 2

    Accepted Solution

    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
    LVL 4

    Expert Comment

    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);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now