473,385 Members | 1,877 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,385 software developers and data experts.

Cannot override paint method

I am trying to modify the way a NumericUpDown control draws itself. I
just need to hide the up/down arrows. I tried overriding both the
OnPaint method and the wm_paint message inside WndProc. Neither way
was successful. The overridden OnPaint method is not being called at
all. WndProc is being called but my changes have no effect, even
though I have successfully done a similar thing with ComboBox. Your
help will be greatly appreciated.

This is my test code. Here I try painting the whole control:

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Select Case m.Msg
Case &HF
Dim g As Graphics = Me.CreateGraphics
Dim r As Rectangle = Me.ClientRectangle
g.FillRectangle(ArrowBrush, r)
Case Else
Exit Select
End Select
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim r As Rectangle = Me.ClientRectangle
e.Graphics.FillRectangle(ArrowBrush, r)
End Sub

thanks
Nov 21 '05 #1
1 4933
Hi,

You need to add the style userpaint to the control to for the paint
event to fire.

Public Sub New()

Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or
ControlStyles.AllPaintingInWmPaint, True)

End Sub

Ken

-------------------------------------

"James Ramaley" <jr******@iname.com> wrote in message
news:f8*************************@posting.google.co m...
I am trying to modify the way a NumericUpDown control draws itself. I
just need to hide the up/down arrows. I tried overriding both the
OnPaint method and the wm_paint message inside WndProc. Neither way
was successful. The overridden OnPaint method is not being called at
all. WndProc is being called but my changes have no effect, even
though I have successfully done a similar thing with ComboBox. Your
help will be greatly appreciated.

This is my test code. Here I try painting the whole control:

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Select Case m.Msg
Case &HF
Dim g As Graphics = Me.CreateGraphics
Dim r As Rectangle = Me.ClientRectangle
g.FillRectangle(ArrowBrush, r)
Case Else
Exit Select
End Select
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim r As Rectangle = Me.ClientRectangle
e.Graphics.FillRectangle(ArrowBrush, r)
End Sub

thanks
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DraguVaso | last post by:
Hi, I want to customize my DataGrid (for VB.NET) a little bit by adding an image to my columnHeaders etc. I need to override the Paint-event of it, but the problem is: I don't know from which...
1
by: sho_nuff | last post by:
Hello, It appears that i may need to create a custom treeview. I have a set of nodes - sometimes, if a user selects an option , i may want to only display a subset of those nodes... and i...
1
by: Craig | last post by:
I've tried to override the paint method and I can't get the overriden paint method to get called. I put the the method below within the class, but it never gets called when I open up my form. By...
18
by: bhavin | last post by:
Hi, Can someone point me to some good best practices kind of documentation on use of events compared to method overriding. Ex. In Windows Forms when should i have an event handler for Paint, and...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
4
by: John Smith | last post by:
Hi All; I am using the HeaderAndDataAlignColumn class from Ken Tucker. I have customized it for a wider row. I reposition the DrawString method so the text is centered vertically in the row. ...
4
by: cok | last post by:
Hi, all I have a question about VS 2005 IDE, I donn't know if It is place to post my question,sorry I have a class inherit form System.Windows.Forms.Form, I want to override OnPaint method ,...
2
by: ad | last post by:
I use login control of VS2005 in my web application. The web applicaiton is developed in my notebook. It run ok in my notebook, but when I login in from another PC with the user ID and password,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.