Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to draw a circle in C#

How to draw a circle in C#

Scheduled Pinned Locked Moved C#
csharptutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    ksaw123
    wrote on last edited by
    #1

    Very good day all, Is there a built in control & classes in C# allow me to draw a circle "dynamically"? like the image in this link? thank you!

    V 1 Reply Last reply
    0
    • K ksaw123

      Very good day all, Is there a built in control & classes in C# allow me to draw a circle "dynamically"? like the image in this link? thank you!

      V Offline
      V Offline
      venomation
      wrote on last edited by
      #2

      Yes there is, in a windows form app you can: private void Form1_Load(object sender, EventArgs e) { Pen pen = new Pen(Color.Black, 3); Graphics gfx = this.CreateGraphics(); gfx.DrawEllipse(pen, 20, 20, 50, 50); } That should get you on the right track :D

      V 1 Reply Last reply
      0
      • V venomation

        Yes there is, in a windows form app you can: private void Form1_Load(object sender, EventArgs e) { Pen pen = new Pen(Color.Black, 3); Graphics gfx = this.CreateGraphics(); gfx.DrawEllipse(pen, 20, 20, 50, 50); } That should get you on the right track :D

        V Offline
        V Offline
        venomation
        wrote on last edited by
        #3

        I made a slight mistake in my last reply, you should actually add the code to the form "paint" event: private void Form1_Paint(object sender, PaintEventArgs e) { Pen pen = new Pen(Color.Black, 3); Graphics gfx = this.CreateGraphics(); gfx.DrawEllipse(pen, 20, 20, 50, 50); } as the form "load" event doesnt apply graphical effects it just initialises its base values. :-D

        K D 2 Replies Last reply
        0
        • V venomation

          I made a slight mistake in my last reply, you should actually add the code to the form "paint" event: private void Form1_Paint(object sender, PaintEventArgs e) { Pen pen = new Pen(Color.Black, 3); Graphics gfx = this.CreateGraphics(); gfx.DrawEllipse(pen, 20, 20, 50, 50); } as the form "load" event doesnt apply graphical effects it just initialises its base values. :-D

          K Offline
          K Offline
          ksaw123
          wrote on last edited by
          #4

          Thanks , I have modfied that , it helps now , the key thing how to create those node on to of them?

          1 Reply Last reply
          0
          • V venomation

            I made a slight mistake in my last reply, you should actually add the code to the form "paint" event: private void Form1_Paint(object sender, PaintEventArgs e) { Pen pen = new Pen(Color.Black, 3); Graphics gfx = this.CreateGraphics(); gfx.DrawEllipse(pen, 20, 20, 50, 50); } as the form "load" event doesnt apply graphical effects it just initialises its base values. :-D

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            A couple of points... 1. Your pen should be disposed (or better still enclosed in a using block.) 2. Any graphics object you create yourself should also be disposed (gfx) 2b. Creating grapics is 'expensive', there is already a Graphics object in e. 3. Better to override the OnPaint method. 3b. You should call the base's method at a suitable location. so the code would become...

            protected override void OnPaint(PaintEventArgs e)
            {
            using (Pen pen = new Pen(Color.Black, 3))
            {
            e.Graphics.DrawEllipse(pen, 20, 20, 50, 50);
            }
            base.OnPaint(e);
            }

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Why are you using VB6? Do you hate yourself? (Christian Graus)

            L 1 Reply Last reply
            0
            • D DaveyM69

              A couple of points... 1. Your pen should be disposed (or better still enclosed in a using block.) 2. Any graphics object you create yourself should also be disposed (gfx) 2b. Creating grapics is 'expensive', there is already a Graphics object in e. 3. Better to override the OnPaint method. 3b. You should call the base's method at a suitable location. so the code would become...

              protected override void OnPaint(PaintEventArgs e)
              {
              using (Pen pen = new Pen(Color.Black, 3))
              {
              e.Graphics.DrawEllipse(pen, 20, 20, 50, 50);
              }
              base.OnPaint(e);
              }

              Dave
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Why are you using VB6? Do you hate yourself? (Christian Graus)

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi Dave,

              DaveyM69 wrote:

              You should call the base's method at a suitable location

              Really? I never do that for Paint, and neither does this MSDN example[^]. So my questions are: why? what does it do for me? and if so, what is "a suitable location"? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Merry Christmas and a Happy New Year to all.


              D 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi Dave,

                DaveyM69 wrote:

                You should call the base's method at a suitable location

                Really? I never do that for Paint, and neither does this MSDN example[^]. So my questions are: why? what does it do for me? and if so, what is "a suitable location"? :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Merry Christmas and a Happy New Year to all.


                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                Because otherwise (if overriding OnPaint rather than handling the Paint event) the Paint event will not get raised. I normally do it at the end of the method i.e. after all painting, however if there is some custom action that needs doing after all paint handlers have finished then base.OnPaint(e) should be called before then. Edit: I've just followed the link a reread your post - In my point before I had suggested overriding OnPaint rather than handling the Paint event which is where the confusion comes from! I prefer to override OnPaint if painting as I can be sure that no subscribers to the Paint event will be called until I've done with painting. If I paint in the Paint event handler then other subscribers may already have been notified yet my painting hasn't even begun!

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Why are you using VB6? Do you hate yourself? (Christian Graus)

                modified on Saturday, January 2, 2010 9:32 AM

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups