Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const EM_GETRECT = &HB2
Private Const EM_SETRECTNP = &HB4
Sub VerMiddleText(mText As TextBox)
If mText.MultiLine = False Then Exit Sub
Dim rc As RECT, tmpTop As Long, tmpBot As Long
SendMessage mText.hwnd, EM_GETRECT, 0, rc
With Me.Font
.Name = mText.Font.Name
.Size = mText.Font.Size
.Bold = mText.Font.Bold
End With
tmpTop = ((rc.Bottom - rc.Top) - _
(mText.Parent.TextHeight("H") \ Screen.TwipsPerPixelY)) \ 2 + 2
tmpBot = ((rc.Bottom - rc.Top) + _
(mText.Parent.TextHeight("H") \ Screen.TwipsPerPixelY)) \ 2 + 2
rc.Top = tmpTop
rc.Bottom = tmpBot
mText.Alignment = vbCenter
SendMessage mText.hwnd, EM_SETRECTNP, 0&, rc
mText.Refresh
End Sub
Private Sub Form_Load()
VerMiddleText Text1
End Sub