ListBox automatically select the item under the mouse

Started by nandagopal, May 20, 2009, 07:07 PM

Previous topic - Next topic

nandagopal

The ItemUnderMouse function returns the index of the item under the mouse. It uses the ClientToScreen API function to convert the (X, Y) coordinates of a point in the ListBox's coordinate system into screen coordinates. It then calls the LBItemFromPt API function to get the index of the item at that point.


' Return the index of the item under the mouse.
Public Function ItemUnderMouse(ByVal list_hWnd As Long, _
    ByVal X As Single, ByVal Y As Single)
Dim pt As POINTAPI

    pt.X = X \ Screen.TwipsPerPixelX
    pt.Y = Y \ Screen.TwipsPerPixelY
    ClientToScreen list_hWnd, pt
    ItemUnderMouse = LBItemFromPt(list_hWnd, pt.X, pt.Y, _
        False)
End Function


The ListBox's MouseMove event handler calls ItemUnderMouse to see what item is under the mouse and then selects it.


' Select the item under the mouse.
Private Sub List1_MouseMove(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    List1.ListIndex = ItemUnderMouse(List1.hwnd, X, Y)
End Sub



dhoni

while creating this code we can easily automatically select item under mouse
from this code we can have automatically easily
in this function it called at any point to know

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview