472,780 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 1911
"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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.