Scrolling textbox programmatically

G

Guest

Hi,

This code (w/c programmatically scrolls a textbox) works in VB 6.0:

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

Private Const EM_LINESCROLL = &HB6

Private Sub Command1_Click()
Dim result As Long
' Textbox should scroll after call below.
result = SendMessage(Text1.hwnd, EM_LINESCROLL, 0, 1)
End Sub

but the same code does not work in VB.NET:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long)
Private Const EM_LINESCROLL As Integer = &HB6

Dim result As Long
result = SendMessage(Textbox1.Handle.ToInt64, EM_LINESCROLL, 0, 1)


result for VB.NET code is always 0. Same happens if hwnd is defined as
IntPtr and Textbox1.Handle is passed to SendMessage. Help please?
 
C

Claes Bergefall

Wrong datatypes. Use this:

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam
As Integer)

Private Const EM_LINESCROLL As Integer = &HB6

Dim result As Integer
result = SendMessage(Textbox1.Handle, EM_LINESCROLL, 0, 1)
 
G

Guest

Worked like a charm! Thanks, Claes :)

Claes Bergefall said:
Wrong datatypes. Use this:

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam
As Integer)

Private Const EM_LINESCROLL As Integer = &HB6

Dim result As Integer
result = SendMessage(Textbox1.Handle, EM_LINESCROLL, 0, 1)
 

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