Set Rich Text Box Control Margin

J

Juan Romero

Guys,

Does anyone know how to set a RichTextControl Left Margin?

I tried using the API but it is not working. I must be doing something
wrong. Here is my code:

Private Const EC_LEFTMARGIN = &H1
Private Const EC_RIGHTMARGIN = &H2
Private Const EC_USEFONTINFO = &HFFFF&
Private Const EM_SETMARGINS = &HD3&
Private Const EM_GETMARGINS = &HD4&

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA"
(ByVal hwnd As IntPtr, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long

Private Sub SetLeftMargin(ByVal lhWnd As IntPtr, ByVal lMargin As Long)
Dim lLongValue As Long
Dim Result As Long
Result = SendMessageLong(lhWnd, EM_SETMARGINS, EC_LEFTMARGIN,
lMargin)
End Sub

The call to the function is:
SetLeftMargin(Me.Handle, 100) 'Me = Richtextbox control

Any ideas?

Thanks!
 
H

Herfried K. Wagner [MVP]

* "Juan Romero said:
Does anyone know how to set a RichTextControl Left Margin?

I tried using the API but it is not working. I must be doing something
wrong. Here is my code:

Private Const EC_LEFTMARGIN = &H1
Private Const EC_RIGHTMARGIN = &H2
Private Const EC_USEFONTINFO = &HFFFF&
Private Const EM_SETMARGINS = &HD3&
Private Const EM_GETMARGINS = &HD4&

Remove the '&' at the end of the constants. 'Long' is a 64-bit datatype
now.
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA"
(ByVal hwnd As IntPtr, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long

'wMsg', 'wParam', and 'lParam' should be declared as 'Int32', the return
value should be an 'Int32' too.
Private Sub SetLeftMargin(ByVal lhWnd As IntPtr, ByVal lMargin As Long)

The same for 'lMargin'.
Dim lLongValue As Long
Dim Result As Long

Dito.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top