Cannot override paint method

  • Thread starter Thread starter James Ramaley
  • Start date Start date
J

James Ramaley

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
 
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

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top