hello
what is the code of if scroll bar of listbox move i

somethins like this ?

if listbox1.scrollmove then 
textbox.text=""
end if

See if this helps.

Public Class Form1
    Private WithEvents tmr As New Timer With {.Enabled = True} '// dynamic.Timer.

    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
        Me.Text = ListBox1.TopIndex '// display the top visible item's Index.
    End Sub
End Class

Add a new class into your project and paste this code:

Imports System.Windows.Forms

Public Class BetterListBox
	Inherits ListBox
	' Event declaration
	Public Delegate Sub BetterListBoxScrollDelegate(Sender As Object, e As BetterListBoxScrollArgs)
	Public Event Scroll As BetterListBoxScrollDelegate
	' WM_VSCROLL message constants
	Private Const WM_VSCROLL As Integer = &H115
	Private Const SB_THUMBTRACK As Integer = 5
	Private Const SB_ENDSCROLL As Integer = 8

	Protected Overrides Sub WndProc(ByRef m As Message)
		' Trap the WM_VSCROLL message to generate the Scroll event
		MyBase.WndProc(m)
		If m.Msg = WM_VSCROLL Then
			Dim nfy As Integer = m.WParam.ToInt32() And &Hffff
			If Scroll IsNot Nothing AndAlso (nfy = SB_THUMBTRACK OrElse nfy = SB_ENDSCROLL) Then
				RaiseEvent Scroll(Me, New BetterListBoxScrollArgs(Me.TopIndex, nfy = SB_THUMBTRACK))
			End If
		End If
	End Sub
	Public Class BetterListBoxScrollArgs
		' Scroll event argument
		Private mTop As Integer
		Private mTracking As Boolean
		Public Sub New(top As Integer, tracking As Boolean)
			mTop = top
			mTracking = tracking
		End Sub
		Public ReadOnly Property Top() As Integer
			Get
				Return mTop
			End Get
		End Property
		Public ReadOnly Property Tracking() As Boolean
			Get
				Return mTracking
			End Get
		End Property
	End Class
End Class

Build your project, then drop a BetterListBox from the top of your toolbox onto your form. Add several items, enough to get a scrollbar. Write a handler for the new Scroll event, something like this:

Private Sub betterListBox1_Scroll(Sender As Object, e As BetterListBox.BetterListBoxScrollArgs)
	Console.WriteLine("Scroll to {0}, tracking={1}", e.Top, e.Tracking)
End Sub

The e.Top property tells you which item is now displayed at the top of the ListBox. e.Tracking is true when the user is dragging the thumb. Note that you'll get at least two Scroll events when the user is dragging, one with e.Tracking = true and another with e.Tracking = false when the user releases the thumb.

OR:
You'll have to add support to the ListView class so you can be notified about scroll events. Add a new class to your project and paste the code below. Compile. Drop the new listview control from the top of the toolbox onto your form. Implement a handler for the new Scroll event.

Imports System.Windows.Forms

Class MyListView
	Inherits ListView
	Public Event Scroll As ScrollEventHandler
	Protected Overridable Sub OnScroll(e As ScrollEventArgs)
		Dim handler As ScrollEventHandler = Me.Scroll
		RaiseEvent handler(Me, e)
	End Sub
	Protected Overrides Sub WndProc(ByRef m As Message)
		MyBase.WndProc(m)
		If m.Msg = &H115 Then
			' Trap WM_VSCROLL
			OnScroll(New ScrollEventArgs(CType(m.WParam.ToInt32() And &Hffff, ScrollEventType), 0))
		End If
	End Sub
End Class

Beware that the scroll position (ScrollEventArgs.NewValue) isn't meaningful, it depends on the number of items in the ListView. I forced it to 0. Following your requirements, you want to watch for the ScrollEventType.EndScroll notification to know when the user stopped scrolling. Anything else helps you detect that the user started scrolling. For example:

Private mLastScroll As ScrollEventType = ScrollEventType.EndScroll

Private Sub myListView1_Scroll(sender As Object, e As ScrollEventArgs)
	If e.Type = ScrollEventType.EndScroll Then
		scrollEnded()
	ElseIf mLastScroll <> ScrollEventType.EndScroll Then
		scrollStarted()
	End If
	mLastScroll = e.Type
End Sub

This seems to be an old post but I tried your solution anyway. Created a class... but VS gives me this error:

Error BC32022 'Public Event Scroll As BetterListBox.BetterListBoxScrollDelegate' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

listboxScroll.png listboxScroll2.png The code is working for me. Afterwards, I've made little changes to it:

Imports System.Windows.Forms

Public Class listboxScroll

    Private Sub BetterListBox1_Scroll(sender As Object, TopIndex As Integer, thumbtrack As Boolean) Handles BetterListBox1.Scroll
        TextBox1.Text += String.Format("Scroll to {0}, thumbtrack is {1}", TopIndex, thumbtrack) + vbCrLf
    End Sub
End Class

Public Class BetterListBox
    Inherits ListBox
    ' Event declaration
    Public Event Scroll(sender As Object, TopIndex As Int32, thumbtrack As Boolean)
    ' WM_VSCROLL message constants
    Private Const WM_VSCROLL As Integer = &H115
    Private Const SB_THUMBTRACK As Integer = 5
    Private Const SB_ENDSCROLL As Integer = 8
    ' Scroll event argument
    Protected Overrides Sub WndProc(ByRef m As Message)
        ' Trap the WM_VSCROLL message to generate the Scroll event
        Try
            MyBase.WndProc(m)
            If m.Msg = WM_VSCROLL Then
                Dim nfy As Integer = m.WParam.ToInt32() And &HFFFF
                If nfy = SB_THUMBTRACK OrElse nfy = SB_ENDSCROLL Then
                    RaiseEvent Scroll(Me, Me.TopIndex, (nfy = SB_THUMBTRACK))
                End If
                End If
        Catch ex As Exception

        End Try
    End Sub

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.