Draw over controls

ShootingStar

Member
Joined
Jul 8, 2005
Messages
5
Programming Experience
3-5
I'm trying to draw a rectangle using GDI+ - very simple.

I want the rectangle to appear when i hover over a control and dissappear when the mouse leaves the control.

This I have accomplished - but I still have problems:

The rectangle is drawn underneath the controls on the form. I want the rectangle to be draw over the controls.

Also I'm getting some serious flickering. After googleing the issue I tried this:

VB.NET:
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
		SetStyle(ControlStyles.UserPaint, True)
		SetStyle(ControlStyles.AllPaintingInWmPaint, True)
		SetStyle(ControlStyles.DoubleBuffer, True)
End Sub

But it hasn't worked!

Any suggestions??
 
Using the SetStyle method as you've shown should take care of the flickering.

To draw on a control, you have to create the graphics object from the control instead of the form. Use Control.CreateGraphics.

Since it seems that you want to draw on several controls, you may need to use the ControlPaint.DrawReversibleFrame method which draws on the screen. Note that the rectangle parameter that you have to supply to this method is in screen coordinates. Calling DrawReversibleFrame a second time (with the same parameters) seems to erase the rectangle except on buttons for some reason. Anyway that may get you started in the right direction.

I'm curious, what is the purpose of drawing the rectangle?
 
Thanks

Thanks for your help. I wanted to draw a rectangele just as an experiment - i'm trying different ways of highlighting controls to the user i.e. borders, color changes etc and i wanted one way of highlighting a group of controls with an area highlighted by a polygon shape. Thanks again.
 
Back
Top