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

  • Thread starter Alexander Vasilevsky
  • Start date
H

Herfried K. Wagner [MVP]

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
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top