Use EM_GETRECT and EM_SETRECTNP will come it true:
At fisrt put a commandbutton and a TextBox to form and set multiLine property of that textbox to true.
then paste the following code to a fome:
Code:
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 Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const EM_SETRECT As Long = &HB3
Private Const EM_GETRECT As Long = &HB2
Private Const EM_SETRECTNP As Long = &HB4
Private Sub Command1_Click()
Dim rc As RECT
Dim tmpTop As Long
Dim tmpBot As Long
Text1.Text = "Centre this text"
Call SendMessage(Text1.hwnd, EM_GETRECT, 0, rc)
With Me.Font
.Name = Text1.Font.Name
.Size = Text1.Font.Size
.Bold = Text1.Font.Bold
End With
tmpTop = ((rc.Bottom - rc.Top) - (Form1.TextHeight("H") \ Screen.TwipsPerPixelY)) \ 2
tmpBot = ((rc.Bottom - rc.Top) + (Form1.TextHeight("H") \ Screen.TwipsPerPixelY)) \ 2
rc.Top = tmpTop
rc.Bottom = tmpBot
Text1.Alignment = vbCenter
Call SendMessage(Text1.hwnd, EM_SETRECTNP, 0&, rc)
Text1.Refresh
End Sub
Posted
Nov 04 2003, 03:06 PM
by
ch21st