VB2005 "Me.Paint" happens before/under controls collection

BrainSlugs83

Member
Joined
Feb 1, 2007
Messages
5
Location
Seattle
Programming Experience
10+
So I have a winform that has a bunch of user controls in it's Controls collection. I'm handing the form's Paint event because I want to use "e.Graphics" to draw on top of the form, and all of it's controls, BUT Paint is being called BEFORE it redraws the other controls, so anything I draw in Paint appears to be underneath my controls. :eek:

Is there a way to change this behavior? Or is there another place I should handle my drawing code? :confused:
 
It wouldn't really make sense to paint the form on top of it's controls since you then wouldn't be able to see the controls.
Perhaps if you explained your goal with the application a solution could be provided.
 
Paszt is correct, but you can get a graphics object to a DC just about anytime and anywhere with...

VB.NET:
Dim e as graphics = graphics.fromhwnd(mybase.handle)

You can then draw on top of your form.
 
interesting, I figured that Graphics.FromHwnd(MyBase.Handle) would do the same thing as Me.CreateGraphics -- I'll give that a try.

For the moment, I just create a for loop that adds handlers to all of the controls (and sub controls of those controls recursively), and I handle their paint events, using their screen location - the window's screen location as the offset for drawing and it's working quite nicely.

I just wanted to be able to drag around sub controls and select them with selection boxes, right now, all selected controls also have a transparent blue box over the top of them so they look just like windows explorer when selected (no they're not files, just user controls).

Anyway, I sort of solved my own problem, but it's pretty damn slow. :-(

My main goal, was just to have a user control (or prebuilt one if one exists) that I can add controls to programatically, you could drag them around with in that control and rearrange them, and they would be "Auto Arrange"-able.

That's what I have now, it works great, but again it's a little laggy.
 
Back
Top