Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSet the margins for a TextBox
DescriptionThis 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.
KeywordsTextBox, margin
CategoriesControls, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated