Drawing GDI types (Rectangle etc) on top of controls (C#)

K

kamleshgk

Hi,
I have a requirement to draw a rectangle and a line on a the
container control and sometimes as i move the mouse the

drawing must occur on top of user controls and other controls, which
are placed in the container control...

I'm using System.Drawing namespace (C#) to perform the drawing.
But as i move the mouse and draw the rectangles, the drawing takes
place behind the user controls....I have a requirement to

draw the shapes on top of the controls...

I scrounged the net to find that there is a WIN 32 style property that
can be set to paint over child controls..
public static int WS_CLIPCHILDREN = 0x02000000;
protected override CreateParams CreateParams
{ get
{ CreateParams cp = base.CreateParams;
cp.Style &= (~WS_CLIPCHILDREN);
return cp;
}
}

This worked!!!! The rectangle was drawn over the child controls.

But this has problems, when ever i tried scrolling the screen there
were lots of flickering and painting issues...
Is there any optimized method/property in the System.Drawing namespace
which can be used to draw over child controls?
Or is there any other way?

Thanx in advance for any help!

Kamlesh
Programmer - Cognizant Technology Solutions
 
C

Christopher Ireland

(e-mail address removed) wrote:
| Hi,
| I have a requirement to draw a rectangle and a line on a the
| container control and sometimes as i move the mouse the

Have a look at the System.Windows.Forms.ControlPaint class.
 
L

Laurent Lequenne

If you put a transparent control above all your other controls... You can
draw what ever you want above everything... If you still need to use mouse
events of underlying controls, you should not forget to define regions into
your transparent control so that mouse events are not captured if the mouse
is on those drawings. This is for the simpliest way :)
 
S

Stoitcho Goutsev \(100\)

There are more than one solution:
1. ControlPaing.DrawReversibleLine or DrawReversibleFrame methods
2. Use some other control that is going to be used as a layer on top of your
controls
3. Remove WS_CLIPCHILDREN style from the user control and draw on the user
control surface.

I'll give my prefernces to the 3., but what ever the case you are going to
have problems handling the mouse down event. If mouse down happens to occur
over child control that very control will receive the event, not the parent
user control. There is no easy way to prefilter mouse events. Even worse
once the mouse is down and the user starts moving the mouse, the control
will set mouse capture and the user control won't receive any mouse move
events even when the mouse is over the usercontrol and outside its parents.
I guess you can handle this by hooking on children's mouse events or using
message filters. The latter my hurt the overall performance of the
application thought.

Here is an example of how to use message filters:
http://groups.google.ca/group/micro...+Message+Filter&rnum=1&hl=en#606da6abeae4716a

Example of how to remove WS_CLIPCHILDREN style:
http://groups.google.ca/group/micro...WS_CLIPCHILDREN&rnum=1&hl=en#2d85705d2c46c1fb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top