none
Creating circles in Vb.net on an image in a picture box

    Question

  • How do i create a circle using the equation of a circle given the coordinates for the centre and the radius of the circle on an image in a picture box.Say the radius of the circle is r and the centre coordinates are (x,y). It will very much appreciated if the source code is given.

    Thanks.

    Friday, April 18, 2008 4:38 PM

Answers

  • All you need to do is create a pen object, a graphics object, and then use some of the pre-defined methods to draw.  Here's a quick example where you create a pen and use the .drawElipse method of the graphics object to draw a circle:

    Code Snippet

            Dim p As New System.Drawing.Pen(Color.Red, 4)
            Dim g As System.Drawing.Graphics
            PictureBox1.Refresh()
            g = PictureBox1.CreateGraphics
            g.DrawEllipse(p, 70, 10, 100, 150)


    Once you start looking at the pen and graphics methods, you'll see how you can change them however you need to.  Hope this helps...

    Friday, April 18, 2008 5:56 PM

All replies

  • All you need to do is create a pen object, a graphics object, and then use some of the pre-defined methods to draw.  Here's a quick example where you create a pen and use the .drawElipse method of the graphics object to draw a circle:

    Code Snippet

            Dim p As New System.Drawing.Pen(Color.Red, 4)
            Dim g As System.Drawing.Graphics
            PictureBox1.Refresh()
            g = PictureBox1.CreateGraphics
            g.DrawEllipse(p, 70, 10, 100, 150)


    Once you start looking at the pen and graphics methods, you'll see how you can change them however you need to.  Hope this helps...

    Friday, April 18, 2008 5:56 PM
  • Thank you FalconDW for your friendly help and support!

     

    Hi GailO,

     

    Welcome to MSDN forums!

      

    Please check this thread for reference:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3177508&SiteID=1

    How to draw image/graphic on PictureBox.Image

    How to draw image/graphic on PictureBox control

     

     

    Best regards,

    Martin

    Thursday, April 24, 2008 8:45 AM