Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hey,

 

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

 

Thanks

What if the Hokey-Pokey IS what it's all about?
Posted

Graphics object

 

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

 

'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:

Never trouble another for what you can do for yourself.
Posted
Thanks for that - will get me started anyways - I haven't got the chance to do much with .NET so I might need to ask another couple of questions yet!
What if the Hokey-Pokey IS what it's all about?
  • Leaders
Posted

If you are drawing on a control, then you should know that each control also supplies a CreateGraphics method.


[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()
[/Code]

 

Note that you should always dispose of your Graphics objects.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...