Groups | Blog | Home
all groups > dotnet windows forms > january 2008 >

dotnet windows forms : How do I know over what element of ListBox is cursor?



Alexander Vasilevsky
1/21/2008 9:02:09 PM
How do I know over what element of ListBox is cursor?

http://www.alvas.net - Audio tools for C# and VB.Net developers

Herfried K. Wagner [MVP]
1/21/2008 10:37:57 PM
"Alexander Vasilevsky" <mail@alvas.net> schrieb:
[quoted text, click to view]

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
AddThis Social Bookmark Button