Simple ToolTips for ListBox Controls [Windows Forms]
I am working on a project right now and I list values in a ListBox, but the text gets cut off when a value is really long. I looked around and while I found custom controls and such, I didn't need anything fancy. Here is a quick fix I found on MSDN.
I am assuming you've added a ToolTip control named MyToolTip to the form and the name of your ListBox is MyListBox.
Private Sub MyListBox_MouseMove(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyListBox.MouseMove
If TypeOf sender Is ListBox Then
Dim lst As ListBox = DirectCast(sender, ListBox)
Dim point As New Point(e.X, e.Y)
Dim hoverIndex As Integer = lst.IndexFromPoint(point)
If hoverIndex >= 0 AndAlso hoverIndex < lst.Items.Count Then
MyToolTip.SetToolTip(lst, lst.Items(hoverIndex).ToString)
End If
End If
End Sub
Thanks to Jesse Bolatto on the ListBox MSDN article.