Tuesday, December 16, 2008

[vb6] Set the margins of a Textbox control

The VB Textbox control superclasses the Windows Edit window class, but doesn't implement its margin property. This procedure sets the left and right margins of a textbox control at run-time, with the margins measured in pixels.
    Private Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lparam As Long)
Private Const EC_LEFTMARGIN& = &H1&
Private Const EC_RIGHTMARGIN& = &H2&
Private Const EM_SETMARGINS = &HD3&

Private Sub SetTextMargin(T As TextBox, ByVal mLeft As Integer, ByVal mRight As Integer)
Dim lparam As Long
lparam = mLeft + mRight * &H10000
SendMessageBynum T.hwnd, EM_SETMARGINS, EC_LEFTMARGIN Or EC_RIGHTMARGIN, lparam
End Sub

No comments:

Post a Comment