473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Stangeness of OnPaint


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
4 1945
"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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
5
by: weixiang | last post by:
Hi, I wrote a progam, which pop up a form that with OnPaint() overrided. It works great in XP but bad in 2K. In 2K, most of the form content will not be displayed until I drag the form a...
5
by: Ron Vecchi | last post by:
I have a custyom control that has a property which wraps a collection. When I add controls to the collection the OnPaint method of these newly added controls never get fired. But if I take the...
20
by: BB | last post by:
Hello all, I am trying to override OnPaint in a custom textbox control (so I can drawstring a caption, etc.). In the code below, I get the "painting the form" message as expected, but not the...
0
by: SirThanxALot | last post by:
Dear all, This prblem is bothering me quite some time now... I have a Panel with a custom panels on top of iet on top of it. Now I need do perform some updates on all of the (15+)....
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
4
by: giddy | last post by:
hi when i run this class i made here , this is what it looks like without text - http://gidsfiles.googlepages.com/LinedTextBox_1.jpg WITH TEXT (heres the issue) -...
1
by: sean | last post by:
I'm trying to create "rubber-band" rectangles by overriding the OnPaint method to place rectangles on top of all graphic controls, but when I call Me.Invalidate() (when the user moves the mouse),...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.