|
|
Title | Set the margins for a TextBox |
Description | This example shows how to set the margins for a TextBox in Visual Basic 6. This program uses the SendMessage API function to send the EM_SETMARGINS message along with appropriate parameters. |
Keywords | TextBox, margin |
Categories | Controls, API |
|
|
This program uses the SendMessage API function to send the EM_SETMARGINS message along with appropriate parameters.
The right margin does not work properly on text that is already entered before the margins are set. To make things work, the program sets the margins and then blanks and resets the text.
|
|
' Set the TextBox's margins.
Private Sub cmdApply_Click()
Dim left_margin As Integer
Dim right_margin As Integer
Dim long_value As Long
left_margin = CInt(txtLeftMargin.Text)
right_margin = CInt(txtRightMargin.Text)
long_value = right_margin * &H10000 + left_margin
SendMessage txtDisplay.hwnd, _
EM_SETMARGINS, _
EC_LEFTMARGIN Or EC_RIGHTMARGIN, _
long_value
' Reset the text to make the right margin work.
Dim txt As String
txt = Me.txtDisplay.Text
Me.txtDisplay.Text = ""
Me.txtDisplay.Text = txt
End Sub
|
|
|
|
|
|