How do I know over what element of ListBox is cursor?

  • Thread starter Thread starter Alexander Vasilevsky
  • Start date Start date
Alexander Vasilevsky said:
How do I know over what element of ListBox is cursor?

Add a ToolTip component to your form, then add this code:

\\\
Private Sub ListBox1_MouseMove( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _
) Handles ListBox1.MouseMove
Dim SourceControl As ListBox = DirectCast(sender, ListBox)
Dim n As Integer = SourceControl.IndexFromPoint(e.X, e.Y)
Dim s As String
If n <> ListBox.NoMatches Then
s = SourceControl.Items(n)
Else
s = ""
End If
If Me.ToolTip1.GetToolTip(SourceControl) <> s Then
Me.ToolTip1.SetToolTip(SourceControl, s)
End If
End Sub
///
 
Back
Top