文本框如果过大,如何让输入的文字居中,上下左右都居中的那种

解决方案 »

  1.   

    左右居中可以通过 .Alignment=VbCenter
    上下暂时无解
      

  2.   

    上下剧中没有好的方法,只能变通形式达到baidu上搜索的'TextBox的MultiLine必须设为True
    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 = &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
    tmpBot = ((rc.Bottom - rc.Top) + _
    (mText.Parent.TextHeight("H") \ Screen.TwipsPerPixelY)) \ 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