Solved

Problem painting NumericUpDown control

Posted on 2004-09-12
12
1,068 Views
Last Modified: 2012-06-27
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, but nothing happens:

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 g As Graphics = Me.CreateGraphics
  Dim r As Rectangle = Me.ClientRectangle
  g.FillRectangle(ArrowBrush, r)
End Sub

thanks
0
Comment
Question by:cyberzork
  • 7
  • 5
12 Comments
 
LVL 8

Expert Comment

by:wguerram
ID: 12044010
Try this:

<DllImport("user32.dll")> _
    Public Shared Function GetWindowDC(ByVal hWnd As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
    End Function

Protected Overrides Sub WndProc(ByRef m As Message)
  MyBase.WndProc(m)
  Select Case m.Msg
    Case &HF
       MyBase.WndProc(m) 'This call is need to take care of some messages you are not handling
       'You have to do this every time you handle the WM_PAINT

       Dim hDC As IntPtr = GetWindowDC(m.HWnd)
       Dim g As Graphics = Graphics.FromHdc(hDC)

       Dim r As Rectangle = Me.ClientRectangle
       'You can also use the bounds property
       g.FillRectangle(ArrowBrush, r)

       ReleaseDC(m.HWnd, hDC)
       g.Dispose
    Case Else
       MyBase.WndProc(m) 'Also make this call
    End Select
End Sub

'Let me know if you have problems



0
 

Author Comment

by:cyberzork
ID: 12054551
Hi wguerram,

Thanks for your help. I tried the code and it paints only a top and left border (width = 1 pixel). We are probably very close to a solution. Any further help will be appreciated.

thanks
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12054735
It looks like the ClientRect is actually bigger than the rect you can draw in.

Try this:

with Me.ClientRectangle
       Dim r As Rectangle = New Rectangle(.X, .Y, .Width - 2, .Height - 2)
End With

Try changin the difference values until you get to paint the border.

if doesn't work try with -3, -4 and so forth.

Let me know what happens.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12054811
Sorry i didn't check you were trying to fill the control.

let me take a look at it.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12055089
I think the problem is because the numeric updown control is composed of four controls:

- TextBox
- Buttons
-The Control container itself

So We are getting the handle of the Control container, that's why its only painting the backside of the control, now we need to get the handle of the textboxes and buttons in order to paint them.

Right now i don't the time to get into it, but as soon as i can i will help you with that.

There must be some kind of message to to get an structures with all handles.
0
 

Author Comment

by:cyberzork
ID: 12061585
thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:cyberzork
ID: 12066082
I am trying to use GetDCEx instead of GetWindowDC. I am not familiar with the Windows API, but I think this should work.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12074363
Could you get GetDCEx to work?
0
 

Author Comment

by:cyberzork
ID: 12081461
No, I couldn't figure out what parameters to pass!
0
 
LVL 8

Accepted Solution

by:
wguerram earned 300 total points
ID: 12084574
I thik i found the solution:

You have to subclass the controls in the numeric updown control

This controls has two controls

dim n as numericupdown

Corresponding to the edit and scrollbar
n.Controls(0)
n.Controls(1)

Now in the new we have to subclass this controls and trap their WM_PAINT messages.

Right now i can't make an example since i have been very busy.

But this should make the work.

we have to use SetWindowLong API
0
 

Author Comment

by:cyberzork
ID: 12086874
Thanks! This is what I needed. I just wanted to hide the scrollbar, which I can do by calling

   Controls(0).Hide

Thanks again. I am increasing your points to 300. You deserve it.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12086922
Yes you are right, you just wanted to hide the controls, i lost the main objective thinking on drawing the control.

Thanks for the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now