473,785 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.PaintEven tArgs)
MyBase.OnPaint( pe)
..
Protected Overrides Sub OnClick(ByVal e As System.EventArg s)
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(Con trolStyles.User Paint, 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(Con trolStyles.User Paint, 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 1973
"dominique" <an*******@Devd ex.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.publi c.dotnet.framew ork.windowsform s
microsoft.publi c.dotnet.framew ork.windowsform s.controls

--
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.Flat Style at Standard, Flat or
Popup, if you change the ButtonBase.Flat Style 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 "Programmin g 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.publi c.dotnet.framew ork.windowsform s
microsoft.publi c.dotnet.framew ork.windowsform s.controls

You might also want to ask in:
microsoft.publi c.dotnet.framew ork.drawing

Hope this helps
Jay
"dominique" <an*******@Devd ex.com> wrote in message
news:uG******** ******@tk2msftn gp13.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.PaintEven tArgs)
MyBase.OnPaint( pe)
.
Protected Overrides Sub OnClick(ByVal e As System.EventArg s)
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(Con trolStyles.User Paint, 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(Con trolStyles.User Paint, 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*******@Devd ex.com> wrote in message
news:e6******** ******@TK2MSFTN GP10.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
6200
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 OnPaint . The recangle draws correct when i press the mouse, but when i release the mouse the background is not restored What should i do in the Onpaint to make sure the background (the form) is restored correctly ? This problem already keeps...
5
1257
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 little. And I set a breakpoint to the OnPaint... The breakpoint was hit when the form popuped... But if I shrink the VS.NET to make it can't overlap with the popup form, the form content is still not displayed after the OnPaint() returned. If I...
5
3087
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 controls in the collection and add them to the custom controls ControlCollection the OnPaint method is called. I would like to use my Collection property but It seems that the controls need to be added to the ControlCollection for them to work....
20
2574
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 "painting the control". It also has no effect to explicitly call txtTest.Invalidate or txtTest.Refresh. Am I missing something simple here? Any push in the right direction is appreciated.
0
1514
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+). Understandably, all the small updates cause the OnPaint method to be called for the different Panel *and* for the containing Panel. However, I want all results to be displayed at once. In other words, how can I wait for all subpanels to be drawn, before...
4
4639
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 program is like so: static void Main() {
4
6029
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) - http://gidsfiles.googlepages.com/LinedTextBox_withText.jpg The text turns BOLD and the lines kinda get erased because of the text. perhaps i could overide or handle the onKeydown or somethin and intercept the text to be entered and then draw it myself. Any suggestions????????
1
3615
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), OnPaint is not getting called... Here is the relevent code: I'm trying to create a "rubber band" rectangle effect on my form. Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles...
14
2974
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 reason you would want to do this is for example to trigger something from an OnPaint event without resorting to boolean switches-- say if a user presses the "M" key while the program is Painting, the user gets the PaintHandler to do something else. ...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.