Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

GDI+ Paint over children controls such as button as well as non-client scrollbar

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Pursley - 08 Apr 2005 21:22 GMT
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?
Bob Powell [MVP] - 08 Apr 2005 23:51 GMT
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>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.