I've been outsmarted by a circle!

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
I seem to always have problems when it comes to graphics. I'm trying to draw a circle in form load. I've finally gotten to the point where I don't get an error, but the circle still doesn't show up. Could someone give me the code to create a circle? Mine is something like this...

VB.NET:
dim mygraphics as graphics = creategraphics()
dim myrectangle as new rectangle(50,50,50,50)
mygraphics.fillelipse(brushes.black,myrectangle)
 
Put it in the form Paint event, and you were missing an L in FillEllipse().

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Paint([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.PaintEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Paint[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] mygraphics [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Graphics = e.Graphics[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myrectangle [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Rectangle(50, 50, 50, 50)[/SIZE]
[SIZE=2]mygraphics.FillEllipse(Brushes.Black, myrectangle)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
That missing l was because I didn't copy and paste my code. That mistake isn't in my code. If there is a way to do it in the form load procedure than I would like to do it like that. The paint event screws things up for me when the form is resized. But there are ways to get around that I guess.

I have finally been able to paint it, but it is beneath my other controls(pictureboxes). how do I paint above these controls?
 
Last edited:
You can call a Refresh() on the Resize event, and don't make your circle a fixed size, make it something like Me.ClientSize.Width - 50, etc. and it should work. I have to try this, but if you use it in the Load event, it might work if you call Refresh. I'm not sure.
 
Back
Top