Re: MVP please help - List box horizontal scroll bar by Ken
Ken
Thu Jul 15 20:04:06 CDT 2004
Hi,
Use the native window class to listen for the scroll messages on
the listbox
' 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
Dim WithEvents sl As MyListener
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
sl = New MyListener(ListBox1)
end sub
Private Sub sl_MyScroll(ByVal sender As Object, ByVal e As System.EventArgs)
Handles sl.MyScroll
Me.Text = "Scroll"
End Sub
Ken
-------------------------------
"Valerie Hough" <sales@pcTrans.com> wrote in message
news:e2YJEksaEHA.3072@TK2MSFTNGP10.phx.gbl...
>I have a list box that uses the horizontal scroll bar. I would like to be
> able to "scroll" my headings at the top of the list box when the list box
> is
> scrolled.
>
> Spy reveals that this is not a real scroll bar (hwnd always null), so I
> can't see how to find out when, and how much, the list box is scrolled.
>
> If I create my own scroll bar, I have trouble keeping the display smooth.
> The best I can seem to do is to intercept and ignore the WM_ERASEBGND
> message, but the effect is still not nearly as smooth as using the
> ListBox.HorizontalScrollBar property. In addition, when I create a
> HScrollBar object and try to anchor it to the bottom of the list box, it
> moves when I vertically scroll the list box. I am reduced to repositioning
> it every time I receive a vertical scroll message.
>
> Obviously I would prefer to use HorizontalScrollBar, but I would settle
> for
> a decent looking scroll effect using HScrollBar.
>
> Can anyone help?
>
> Thanks in advance,
> Valerie Hough
>
>