Auto scroll

  • Thread starter Thread starter Stephen Haunts
  • Start date Start date
S

Stephen Haunts

Hi

Ive got a custom usercontrol that has the autoscroll property enabled so
that the scroll bars appear when the control is smaller that what it's
containing.

Is is possible to get an event notification for when the user moved the
scroll bars. I know you can do this with scroll bars from the toolbox but
can you with autoscroll scroll bars.

Cheers

Steve
 
Hi,

You can use the nativewindows class to do that. Here is a
simple example.

' NativeWindow class to listen to operating system messages.

Private Class MyListener

Inherits NativeWindow

Public Event MyScroll(ByVal sender As Object, ByVal e As EventArgs)

Const WM_MOUSEACTIVATE = &H21

Const WM_MOUSEMOVE = &H200



Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)

End Sub

Protected Overrides Sub WndProc(ByRef m As Message)

' Listen for operating system messages

Const WM_HSCROLL = &H114

Const WM_VSCROLL = &H115





If m.Msg = WM_Hscroll Or m.Msg = wm_vscroll Then

RaiseEvent MyScroll(ctrl, New EventArgs)

End If

MyBase.WndProc(m)

End Sub

Protected Overrides Sub Finalize()

ReleaseHandle()

MyBase.Finalize()

End Sub

End Class



How to use

Dim WithEvents sl As New MyListener(ListBox1)

Private Sub sl_MyScroll(ByVal sender As Object, ByVal e As System.EventArgs)
Handles sl.MyMouseMove

Me.Text = "Scroll"

End Sub

Ken
 
Back
Top