Solved

Tracking the mouse in a list box

Posted on 2004-10-27
204 Views
Last Modified: 2010-05-02
I'd like to be able to set the tooltip of a list box based on the entry the mouse is over a list box. Can anyone tell me how this can be accomplished ?

Thanks !
0
Question by:levinlll
    4 Comments
     
    LVL 85

    Accepted Solution

    by:
    Option Explicit

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hWnd As Long, ByVal wMsg As Long, _
        ByVal wParam As Long, lParam As Long) As Long

    Private Sub Form_Load()
        Dim i As Integer
       
        For i = 1 To 10
            List1.AddItem "Item " & i
        Next
    End Sub

    Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim idx As Integer
        idx = ListRowCalc(List1, Y)
        List1.ToolTipText = List1.List(idx)
    End Sub
       
    Private Function ListRowCalc(lstTemp As Control, ByVal Y As Single) As Integer
        Const LB_GETITEMHEIGHT = &H1A1
       
        Dim ItemHeight As Integer
        ItemHeight = SendMessage(lstTemp.hWnd, LB_GETITEMHEIGHT, 0, 0)
        ListRowCalc = min(((Y / Screen.TwipsPerPixelY) \ ItemHeight) + _
            lstTemp.TopIndex, lstTemp.ListCount - 1)
    End Function

    Private Function min(X As Integer, Y As Integer) As Integer
        If X > Y Then min = Y Else min = X
    End Function
    0
     
    LVL 76

    Expert Comment

    by:GrahamSkan
    ListBox1.Tooltip = "My tooltip"
    This seems too simple, so I may have misunderstood
    0
     
    LVL 76

    Expert Comment

    by:GrahamSkan
    Yes. It was too simple. I had misunderstood.
    0
     
    LVL 8

    Expert Comment

    by:Ashutosh Vyas
    Private Sub List1_MouseMove()
              List1.ToolTip = "ToolTip Text here"
    End Sub
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now