Make your own free website on

Set Text Box Right And Left Margins

'Add 1 Command Button and 3 Text Boxes to your form.
'Set Text1 MultiLine Property to True.
'At Run-Time, insert the Text Box left margin to Text2, and the right margin to Text3,
'and press the button to apply the changes.

'Insert the following code to your form:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal _
lParam As Long) As Long
Private Const EM_SETMARGINS = &HD3
Private Const EC_LEFTMARGIN = &H1
Private Const EC_RIGHTMARGIN = &H2

Private Sub Command1_Click()
End Sub

Private Sub Form_Load()
Text2 = "30"
Text3 = "30"
Text1.Text = "This program shows how to set the left and right margins _
of a TextBox." & vbCrLf & " Its been taken from"
End Sub

Private Sub SetMargins()
Dim left_margin As Integer
Dim right_margin As Integer
Dim long_value As Long
left_margin = CInt(Text2.Text)
right_margin = CInt(Text3.Text)
long_value = left_margin * &H10000 + right_margin
SendMessage Text1.hwnd, _
End Sub

Go Back