How to set Text Box Left and Right Margins
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 'Controls - How to set Text Box Left and Right Margins Option Explicit 'Add a Command Button and three 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. 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() SetMargins End Sub Private Sub Form_Load() Text2 = "30" Text3 = "30" SetMargins Text1.Text = "some sort of text here. www.codeitbetter.com - " & vbCrLf & " Your Handy source code Library" End Sub Private Sub SetMargins() Dim left_margin As Integer, 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, EM_SETMARGINS, EC_LEFTMARGIN Or EC_RIGHTMARGIN, long_value End Sub |