OK, unfortunately, the regular textbox control doesn't have scroll events. That's a pain. The RichTextbox control, on the other hand, does. So this is easier with a rich text control. You can do the following:
Const WM_USER As Integer = &H400
Const EM_GETSCROLLPOS As Integer = WM_USER + 221
Const EM_SETSCROLLPOS As Integer = WM_USER + 222
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByRef lParam As Point) As Integer
Private Sub RichTextBox1_VScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.VScroll
Dim pt As Point
SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, 0, pt)
SendMessage(RichTextBox2.Handle, EM_SETSCROLLPOS, 0, pt)
End Sub
Every time you scroll (vertically) on richtextbox1, you set the scroll position on richtextbox2. You can also do the same in the HScroll event to capture horizontal scrolling.
If you *need* to do this with a regular textbox, then you have to create a custom textbox by inheriting the textbox class, and overriding the wndproc method to look for scrolling messages, then fire a custom scrolling event. To keep it simple, I'd rather use the richtextbox control.
-Rob Teixeira |