Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 12,200 times

Related Categories

Margins in a TextBox

This code allows you to set the margins for a textbox

Simply call SetMargin with the left and right margins, along with the hWnd of the textbox that you want changed. Note that to set the right margin, you need to have align set to right, and vice-versa.

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

' Set the TextBox's margins.
Private Sub SetMargin(nLeft As Integer, nRight As Integer, lhWnd As Long)
Dim lLongValue As Long

    'nRight needs to be in the hi-word, so we multiply by 65536
    lLongValue = 65536 * nRight + nLeft

    SendMessage lhWnd, EM_SETMARGINS, _
        EC_LEFTMARGIN Or EC_RIGHTMARGIN, lLongValue
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments