How to determine that a scroll event occured

  • Thread starter Thread starter Lance
  • Start date Start date
L

Lance

I need to know when the user scrolls a Windows.Forms.Panel
either by using one of the scroll buttons or by using one
of the scrollbars. Are there any events or overridable
methods that can be used to detect this?

Thanks,
Lance
 
Hi,

Check to see if the autoscrollpostion has changed in the paint event
of the panel. Or create an inherited control. Override wndproc you will
recieve the WM_HSCROLL or WM_VSCROLL messages when the panel scrolls.
<ToolboxBitmap(GetType(Panel))> _

Public Class PanelScroll

Inherits System.Windows.Forms.Panel

Public Event Scroll(ByVal sender As Object, ByVal e As EventType)

Private Const WM_VSCROLL = &H115

Private Const WM_HSCROLL = &H114

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

Me.HorizontalScrollbar = True

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

components = New System.ComponentModel.Container

End Sub

#End Region

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Dim Bytes, b As Byte()

If m.Msg = WM_VSCROLL Or m.Msg = WM_HSCROLL Then

RaiseEvent Scroll(Me, New EventArgs)

End If

MyBase.WndProc(m)

End Sub



End Class

Ken
 
Back
Top