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
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Function SetVCenterText(userdefineTextBox As TextBox)

   Dim rc As RECT

   Dim UserControlTop As Long

   Dim UserControlBottom As Long

   If userdefineTextBox.MultiLine = False Then Exit Function

   Call SendMessage(userdefineTextBox.hwnd, EM_GETRECT, 0, rc)

   UserControlTop = ((rc.Bottom - rc.Top) - (UserControl.Parent.TextHeight("H") \ Screen.TwipsPerPixelY)) \ 2

   UserControlBottom = ((rc.Bottom - rc.Top) + (UserControl.Parent.TextHeight("H") \ Screen.TwipsPerPixelY)) \ 2

   rc.Top = UserControlTop

   rc.Bottom = UserControlBottom

   userdefineTextBox.Alignment = vbCenter

   Call SendMessage(userdefineTextBox.hwnd, EM_SETRECTNP, 0&, rc)

   userdefineTextBox.Refresh
End Function

Private Sub UserControl_Resize()
    Text1.Top = 0
    Text1.Left = 0
    Text1.Height = UserControl.Height
    Text1.Width = UserControl.Width
   
    SetVCenterText Text1
End Sub

相关文章:

  • 2021-08-31
  • 2021-08-21
  • 2021-08-31
  • 2021-09-23
  • 2021-11-27
  • 2022-12-23
  • 2021-08-07
  • 2021-12-02
猜你喜欢
  • 2021-08-31
  • 2021-12-14
  • 2021-12-04
  • 2021-12-14
  • 2021-08-31
  • 2021-11-22
  • 2021-11-17
相关资源
相似解决方案