Tools Links Login

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.

Original Author: unknown

Assumptions

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 :(

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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 116 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.