By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,896 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,896 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Sep 25 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ka*******@gmail.com 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.

--
Christopher Ireland

"You can't have everything. Where would you put it?"
Steven Wright
Sep 25 '06 #2

P: n/a
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 :-)
<ka*******@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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

Sep 25 '06 #3

P: n/a
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/micros...6da6abeae4716a

Example of how to remove WS_CLIPCHILDREN style:
http://groups.google.ca/group/micros...85705d2c46c1fb


--
HTH
Stoitcho Goutsev (100)

<ka*******@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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

Sep 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.