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

Stangeness of OnPaint

P: n/a

Hi,

In windows forms (vb.net), i use my own controls subclassed from base
controls and i override the Onxxx methods.

for example:
Public Class MyBouton
Inherits System.Windows.Forms.Button
..
Protected Overrides Sub OnPaint(ByVal pe As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)
..
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
Mybase.OnClick(e)
..

I saw that :
- for some controls (ex: combobox), i can't access to OnPaint but i can
access to OnClick ..
- for these controls, if i had in the constructor :
Me.SetStyle(ControlStyles.UserPaint, true)
i can now access to OnPaint (then i must draw the control even if i put
MyBase.OnPaint(pe))
but if i put : Me.SetStyle(ControlStyles.UserPaint, false)
i can't access to none Onxxx

- in some controls (ex: Button) without Me.SetStyle, it is ok, i can
access to OnPaint

I saw also if i intercept a windows message, it is ok :

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Select Case m.Msg
Case &HF ' =15 =Paint

Can anybody explain this stangeness ?
Is it a known bug ?

Is it better to use always windows message instead of OnPaint ?

Thanks for advice.

Dominique Gratpain

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"dominique" <an*******@Devdex.com> schrieb:
In windows forms (vb.net), i use my own controls subclassed
from base controls and i override the Onxxx methods.


If you don't get an answer here, consider posting to the Windows Forms
group:

microsoft.public.dotnet.framework.windowsforms
microsoft.public.dotnet.framework.windowsforms.con trols

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2

P: n/a
dominique,
- for some controls (ex: combobox), i can't access to OnPaint but i can
access to OnClick .. ComboBox's support something called Owner Draw, you need to handle the
OnDrawItem event instead of OnPaint.
- in some controls (ex: Button) without Me.SetStyle, it is ok, i can
access to OnPaint That's only true if you leave ButtonBase.FlatStyle at Standard, Flat or
Popup, if you change the ButtonBase.FlatStyle to System (to gain Win XP
theme support) then you cannot access OnPaint.

NOTE: I'm curious if this holds true for VS.NET 2005 (currently in beta, due
out next year) as they have improved the theming support.
Can anybody explain this stangeness ? Charles Petzold's book "Programming Microsoft Windows with Microsoft Visual
Basic .NET - Core Reference" from MS Press covers almost all the Windows
Forms controls and how to do custom painting in each.
Is it a known bug ? I would say a limitation of Windows itself, which unfortunately is carried
into the framework, as the Framework is a wrapper around the Win32 controls.

Is it better to use always windows message instead of OnPaint ? I would favor OnPaint & OnDrawItem over WndProc & dealing with the windows
message itself, as OnPaint & OnDrawItem already take care of all the interop
stuff, they give me a Graphics object, instead of needing to create one from
a Win32 handle...

In addition to

microsoft.public.dotnet.framework.windowsforms
microsoft.public.dotnet.framework.windowsforms.con trols

You might also want to ask in:
microsoft.public.dotnet.framework.drawing

Hope this helps
Jay
"dominique" <an*******@Devdex.com> wrote in message
news:uG**************@tk2msftngp13.phx.gbl...
Hi,

In windows forms (vb.net), i use my own controls subclassed from base
controls and i override the Onxxx methods.

for example:
Public Class MyBouton
Inherits System.Windows.Forms.Button
.
Protected Overrides Sub OnPaint(ByVal pe As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)
.
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
Mybase.OnClick(e)
.

I saw that :
- for some controls (ex: combobox), i can't access to OnPaint but i can
access to OnClick ..
- for these controls, if i had in the constructor :
Me.SetStyle(ControlStyles.UserPaint, true)
i can now access to OnPaint (then i must draw the control even if i put
MyBase.OnPaint(pe))
but if i put : Me.SetStyle(ControlStyles.UserPaint, false)
i can't access to none Onxxx

- in some controls (ex: Button) without Me.SetStyle, it is ok, i can
access to OnPaint

I saw also if i intercept a windows message, it is ok :

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Select Case m.Msg
Case &HF ' =15 =Paint

Can anybody explain this stangeness ?
Is it a known bug ?

Is it better to use always windows message instead of OnPaint ?

Thanks for advice.

Dominique Gratpain

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #3

P: n/a

Thanks Jay and Herfried for yours answers.

It is strange that the IDE suggest the OnPaint event for the ComboBox
subclass even thought it doesn't work .. but perharps it is because the
class was an user control before to become a combobox.

I am going to post this question in the three newsgroups you suggest.

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4

P: n/a
Dominique,
ComboBox inherits from Control (not UserControl).

Seeing as OnPaint is a member of Control, ComboBox has an OnPaint method.

Hope this helps
Jay
"dominique" <an*******@Devdex.com> wrote in message
news:e6**************@TK2MSFTNGP10.phx.gbl...

Thanks Jay and Herfried for yours answers.

It is strange that the IDE suggest the OnPaint event for the ComboBox
subclass even thought it doesn't work .. but perharps it is because the
class was an user control before to become a combobox.

I am going to post this question in the three newsgroups you suggest.

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.