.NET equivalent to Me.Circle?

joker77

Active member
Joined
Sep 16, 2005
Messages
38
Location
Dublin
Hey,

Just wondering is there any .NET equivalent to the Me.Circle method on a form for drawing a circle?

Thanks
 
Graphics object

Indeed there is an equivalent - .NET would appear a poor technology if something as simple as drawing a circle on a window wasnt possible ;). However, the method of doing so has changed a little from VB6. All drawing operations must be performed on a Graphics object. If youre drawing in the Paint event then a Graphics object is passed within the PaintEventArgs:

Code:
Assumes the following Imports:
Imports System.Windows.Forms
Imports System.Drawing

    Paint event
    Private Sub MyForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint

        Draw a blue circle 40 pixels in diameter in the center of the form
        e.Graphics.DrawEllipse(Pens.Blue, _
            CType((Me.ClientSize.Width / 2) - 20, Integer), _
            CType((Me.ClientSize.Height / 2) - 20, Integer), _
            40, 40)

    End Sub

If you wish to draw the circle at some other point in the code then you will have to create a Graphics object using the hWnd of the form or its BackgroundImage.

Good luck :cool:
 
Thanks for that - will get me started anyways - I havent got the chance to do much with .NET so I might need to ask another couple of questions yet!
 
If you are drawing on a control, then you should know that each control also supplies a CreateGraphics method.
Code:
[COLOR="SeaGreen"]Draw a circle that extends to the edges of SomeControl[/COLOR]
[COLOR="Blue"]Dim[/COLOR] g [COLOR="Blue"]As[/COLOR] Graphics = SomeControl.CreateGraphics()
g.DrawEllipse( _
    Pens.Black, SomeControl.Bounds)
g.Dispose()

Note that you should always dispose of your Graphics objects.
 
Back
Top