|
|
Title | Synchronize two scrolling Panel controls in Visual Basic .NET |
Description | This example shows how to synchronize two scrolling Panel controls in Visual Basic .NET. |
Keywords | scroll, Panel, AutoScroll, scroll event, synchronize, VB.NET |
Categories | Controls, VB.NET |
|
|
Thanks to Adam Kelly.
This example uses the ScrollPanel control, which inherits from the Panel control. It overrides its WndProc subroutine to look for the WM_HSCROLL and WM_VSCROLL messages and raises its Scroll event when it detects one.
|
|
<ToolboxBitmap(GetType(ScrollPanel), _
"ScrollPanelTool.bmp")> _
Public Class ScrollPanel
Inherits Panel
Public Event Scroll(ByVal sender As Object)
Public Const WM_HSCROLL As Integer = &H114
Public Const WM_VSCROLL As Integer = &H115
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_HSCROLL Then
RaiseEvent Scroll(Me)
ElseIf m.Msg = WM_VSCROLL Then
RaiseEvent Scroll(Me)
End If
MyBase.WndProc(m)
End Sub
End Class
|
|
When the program receives a Scroll event from either of its ScrollPanel controls, it uses that control's AutoScrollPosition property to get the scrollbar settings and then sets the same settings for the other ScrollPanel.
|
|
Private Sub panLeft_Scroll(ByVal sender As Object) Handles _
panLeft.Scroll
panRight.AutoScrollPosition = New Point( _
-panLeft.AutoScrollPosition.X, _
-panLeft.AutoScrollPosition.Y)
End Sub
Private Sub panRight_Scroll(ByVal sender As Object) Handles _
panRight.Scroll
panLeft.AutoScrollPosition = New Point( _
-panRight.AutoScrollPosition.X, _
-panRight.AutoScrollPosition.Y)
End Sub
|
|
|
|
|
|