NumericUpDown vertical textalignment
I'm trying to vertically centre the text in a NumericUpDown control. I'm fairly sure there's no property i can change, but is there an API i could use? Does anyone have any experience with this?
I tried this, and it didn't work...
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As RECT _
) As Integer
Private Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Private Const EM_SETRECT As Integer = &HB3
Private Const EM_GETRECT As Integer = &HB2
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each nud As NumericUpDown In Me.Controls.OfType(Of NumericUpDown)()
Dim tb As TextBox = DirectCast(nud.Controls(1), TextBox)
Dim myRect As New RECT
Dim sf As New SizeF
sf = tb.CreateGraphics.MeasureString("1", tb.Font)
'set rectangle to match text height and center it
Dim textHeight As Integer = CInt(sf.Height)
'Dim boxHeight As Integer = tb.ClientSize.Height
myRect.Left = 0
myRect.Right = tb.ClientSize.Width
myRect.Top = 2
myRect.Bottom = myRect.Top + textHeight
SendMessage(tb.Handle, EM_SETRECT, 0, myRect)
Next
End Sub
Anyone know how to do this?