VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Display long text in tooltiptext in listbox


Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

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.

Assumes
Just place a list box on a form (less than 25 lines to see the scrolling ability. More than 25 to see empty space handling)
Side Effects
On slow PC's with alot of stuff running the tipbox will appear to flash :(

Rate Display long text in tooltiptext in listbox

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

Download this snippet    Add to My Saved Code

Display long text in tooltiptext in listbox Comments

No comments have been posted about Display long text in tooltiptext in listbox. Why not be the first to post a comment about Display long text in tooltiptext in listbox.

Post your comment

Subject:
Message:
0/1000 characters