I am trying to paint in a custom control "OnPaint" but can not paint over the child controls such as a button or listview. I also want to be able to paint in the "Bounds" region of the control over the scrollbars in a ScollableControl. Any ideas?
There are two ways to put drawings on top of child controls. The first is to
draw directly on the desktop. The second is to use a layered window and put
that on top of everything else.
To draw on the desktop you need a wee bit of interop to import the GetDC and
ReleaseDC methods. Get a DC for the desktop using null as a window handle,
wrap the returned DC in a Graphics object using Graphics.FromHdc, Draw on
the desktop, dispose of the Graphics object and release the DC again.
If you search in the VB group you'll find an answer I gave someone an answer
with a layered window solution.
The post was dated 30th march and entitled "Re: Using The NativeWindow Class
To Draw A GDI Type Circle On Top Of A DataGrid Possibly In The Override
OnPaint"

Signature
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
>I am trying to paint in a custom control "OnPaint" but can not paint over
>the child controls such as a button or listview. I also want to be able to
[quoted text clipped - 7 lines]
>
> <Id>5ywHB/dgkUStAiKjTE/f5w==</Id>
Stoitcho Goutsev \(100\) [C# MVP] - 09 Apr 2005 00:10 GMT
One other soluion for the control which are positioned over the control's
client area would be the following:
Controls cannot draw over their children because by default all windows have
WS_CLIPCHILDREN style set. With this style all space occupied by child
controls is clipped off of the control's client area.
What one can do in this case is to override CreateParams virtual property
and exlude this flag from the styles that the base implenetation returns
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style &= (~WS_CLIPCHILDREN);
return cp;
}
WS_CLIPCHILDREN is 0x02000000
This won't work though for controls, which are outside the client rectangle
such as scrollbars, menu, etc

Signature
Stoitcho Goutsev (100) [C# MVP]
> There are two ways to put drawings on top of child controls. The first is
> to draw directly on the desktop. The second is to use a layered window and
[quoted text clipped - 24 lines]
>>
>> <Id>5ywHB/dgkUStAiKjTE/f5w==</Id>