Получите информацию о прокрутке для обоих элементов управления:
Сначала вам понадобятся следующие win32 API ( Импортирует System.Runtime.InteropServices ) в ваш проект
<DllImport("user32.dll")> _
Private Shared Function GetScrollInfo(ByVal hwnd As IntPtr, ByVal fnBar As Integer, ByRef lpsi As SCROLLINFO) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function SetScrollInfo(ByVal hwnd As IntPtr, ByVal fnBar As Integer, <[In]()> ByRef lpsi As SCROLLINFO, ByVal fRedraw As Boolean) As Integer
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, EntryPoint:="SendMessage")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
End Function
'added by edit
Private Const SB_THUMBTRACK As Integer = 5
Private Const WM_VSCROLL As Integer = &H115
Private Const WM_HSCROLL As Integer = &H114
Public Declare Function SetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer, _
ByVal nPos As Integer, _
ByVal bRedraw As Boolean) As Integer
Private Structure SCROLLINFO
Public cbSize As UInteger
Public fMask As UInteger
Public nMin As Integer
Public nMax As Integer
Public nPage As UInteger
Public nPos As Integer
Public nTrackPos As Integer
End Structure
Private Enum ScrollBarDirection
SB_HORZ = 0
SB_VERT = 1
SB_CTL = 2
SB_BOTH = 3
End Enum
Private Enum ScrollInfoMask
SIF_RANGE = &H1
SIF_PAGE = &H2
SIF_POS = &H4
SIF_DISABLENOSCROLL = &H8
SIF_TRACKPOS = &H10
SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
End Enum
'create some public properties to get and set scroll position for any scrollable control:
Public Property _VerticalScroll(ByVal hwnd As IntPtr) As Integer
Get
Dim si As New SCROLLINFO()
si.cbSize = CUInt(Marshal.SizeOf(si))
si.fMask = CUInt(ScrollInfoMask.SIF_ALL)
GetScrollInfo(hwnd, CInt(ScrollBarDirection.SB_VERT), si)
Return si.nPos
End Get
Set(ByVal value As Integer)
Dim si As New SCROLLINFO()
si.cbSize = CUInt(Marshal.SizeOf(si))
si.fMask = CUInt(ScrollInfoMask.SIF_ALL)
GetScrollInfo(hwnd, CInt(ScrollBarDirection.SB_VERT), si)
If value > si.nMax Then
value = si.nMax
End If
Dim ptrWparam = New IntPtr(SB_THUMBTRACK + &H10000 * value)
SetScrollPos(hwnd, Orientation.Vertical, value, True)
PostMessage(hwnd, WM_VSCROLL, ptrWparam, IntPtr.Zero)
End Set
End Property
Public Property _HorizontalScroll(ByVal hwnd As IntPtr) As Integer
Get
Dim si As New SCROLLINFO()
si.cbSize = CUInt(Marshal.SizeOf(si))
si.fMask = CUInt(ScrollInfoMask.SIF_ALL)
GetScrollInfo(hwnd, CInt(ScrollBarDirection.SB_HORZ), si)
Return si.nPos
End Get
Set(ByVal value As Integer)
Dim si As New SCROLLINFO()
si.cbSize = CUInt(Marshal.SizeOf(si))
si.fMask = CUInt(ScrollInfoMask.SIF_ALL)
GetScrollInfo(hwnd, CInt(ScrollBarDirection.SB_HORZ), si)
If value > si.nMax Then
value = si.nMax
End If
Dim ptrWparam = New IntPtr(SB_THUMBTRACK + &H10000 * value)
SetScrollPos(hwnd, Orientation.Horizontal, value, True)
PostMessage(hwnd, WM_HSCROLL, ptrWparam, IntPtr.Zero)
End Set
End Property
ваш следующий шаг - отслеживать, какая полоса прокрутки изменяется .... с помощью таймера и т. д., а затем обновлять другой элемент управления при необходимости.