CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: List box

  1. #1
    Join Date
    Nov 1999
    Posts
    10

    List box

    Dear sir,

    i want to show a tool tip in mouse move event for a list box. when a user moves the mouse over an item in list box, he should be able to see same item name as a tool tip for the list box.

    thanks in advance,
    anand






  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: List box

    Try this:

    private Type POINTAPI
    X as Long
    Y as Long
    End Type

    private Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long
    private Declare Function ScreenToClient Lib "user32" (byval hWnd as Long, lpPoint as POINTAPI) as Long
    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 Const LB_ITEMFROMPOINT = &H1A9

    private Sub Form_Load()
    Dim iIndex as Integer
    'Fill the List with Dummy Values
    for iIndex = 1 to 100
    List1.AddItem "Really Long List Item " & iIndex
    next
    End Sub

    private Sub List1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
    Dim tPOINT as POINTAPI
    Dim iIndex as Long

    'get the Mouse Cursor Position
    Call GetCursorPos(tPOINT)
    'Convert the Coords to be Relative to the Listbox
    Call ScreenToClient(List1.hWnd, tPOINT)
    'Find which Item the Mouse is Over
    iIndex = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0&, byval ((tPOINT.X And &HFF) Or (&H10000 * (tPOINT.Y And &HFF))))
    If iIndex >= 0 then
    'Extract the List Index
    iIndex = iIndex And &HFF
    'set the Lists ToolTipText
    List1.ToolTipText = List1.List(iIndex)
    End If
    End Sub




    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured