试试看'TextBox的MultiLine必须设为TruePrivate 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 = &HB4Sub 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 SubPrivate Sub Form_Load() VerMiddleText Text1 End Sub
所以不知你是什么目的,若仅仅是为显示出来的东西有文本框效果,又想垂直居中美观一些的话,完全可用PictureBox代替。
楼上的这位赐教!
我就搞不懂,这个球textbox咋就没有垂直居中这个属性呢!
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 = &HB4Sub 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 SubPrivate Sub Form_Load()
VerMiddleText Text1
End Sub
1、用一个Label代替显示,单击时出来一个文本框就可以了。
2、数据保存起来,显示的是经过处理的数据,并不难;例如:值="232323",显示:=" 232323"
3、用一个类模块把文本框包装一下,可以用上面的原理。