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 / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

How to override the Form.OnPaint method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom P. - 12 Mar 2008 20:02 GMT
I am trying to take over the painting of a windows form but I can't
seems to override the OnPaint method... or the OnPaintBackground
method... or even the OnNotifyMessage method if there is a control
covering the client area. None of these are getting called in any way.
I've tried using SetStyle(ControlStyles.AllPaintingInWmPaint, true);
and SetStyle(ControlStyles.UserPaint, true); but nothing works. If
there is no client area the OnPaint is never getting called. Is there
a different method for painting the actual Form? How do I repaint the
titlebar and menus and everything?

How do I actually override the entire OnPaint method for the form?

Tom P.
RobinS - 16 Mar 2008 04:22 GMT
How about if you bring up the form in design mode. Go to the form properties
window, click on the lightning bolt to bring up the available events, find
Paint. Double-click on the blank space next to it. This will add an
eventhandler to your code-behind for the painting of the form.

Will it completely override? I don't nkow. Try it and see.

RobinS.
GoldMail.com

>I am trying to take over the painting of a windows form but I can't
> seems to override the OnPaint method... or the OnPaintBackground
[quoted text clipped - 9 lines]
>
> Tom P.
Peter Duniho - 16 Mar 2008 05:32 GMT
> How about if you bring up the form in design mode. Go to the form  
> properties window, click on the lightning bolt to bring up the available  
[quoted text clipped - 3 lines]
>
> Will it completely override? I don't nkow. Try it and see.

It won't.  It will handle the Paint event, not override OnPaint().

But Tom's question isn't really about overriding OnPaint().  Overriding  
that method is easy.  You just add a new OnPaint() method in your subclass  
with the keyword "override".  That's not what he's asking about though (in  
spite of this inaccurate subject line).

He really wants to override the non-client rendering of the window.  As  
far as I know, there's no way to do this directly from .NET.  I think it's  
possible that if he overrides the WndProc() method and handles the  
NC_PAINT messages himself it _might_ work.  But I don't really know enough  
about how .NET and the underlying unmanaged window class interact to know  
for sure.

Pete
Tom P. - 16 Mar 2008 06:06 GMT
On Mar 15, 11:32 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > How about if you bring up the form in design mode. Go to the form
> > properties window, click on the lightning bolt to bring up the available
[quoted text clipped - 19 lines]
>
> Pete

Thanks again Pete,

I should have known you'd be the one to point me in the right
direction.  WM_NCPAINT is the message I was supposed to capture but I
still wasn't able to paint in the Non-client area. After a bit more
poking I discovered that Vista does some special stuff during the non-
client paint and it's best to just leave it alone. I'll have to
subclass some of the other controls in my client area (like the
menubar and toolstrip) to do the skinning I want but the window frame
and NC area are out of my league.

Now on to why Vista doesn't handle string trimming correctly.

Tom P.

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.