Display long text in tooltiptext in listbox
This code displays the text on the line the mouse is over in the tooltiptext box. This is useful for when your text string is longer than the textbox can display.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Private Sub Form_Load()
'load a bunch of long messages in the listbox
For i = 0 To 25
List1.AddItem (i & ". This is a long string that you can't _
see all of in the list box, it's #: " & i)
Next i
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
'the height of the default text (you will have to change this
'if you change the font size)
WordHeight = 195
'go through the loop until you get to the file
For i = 0 To List1.ListCount - 1
'check to what line the text is over (you need to go
'through the whole list in case you've scrolled down
If Y > WordHeight * (i - List1.TopIndex) _
And Y < (WordHeight * i + WordHeight) Then
'set the tooltiptext to the list box value
List1.ToolTipText = List1.List(i)
'see if your in "empty space"
ElseIf Y > (WordHeight * i + WordHeight) Then
List1.ToolTipText = "Empty space"
End If
Next i
End Sub
Original Comments (3)
Recovered from Wayback Machine