|
Данный пример покажет, как можно автоматически выделить строчку в элементе ListBox, при прохождении над ним курсора мыши. 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
Const LB_GETITEMHEIGHT = &H1A1
Private Sub Form_Load()
List1.AddItem "aaa"
List1.AddItem "bbb"
List1.AddItem "ccc"
List1.AddItem "ddd"
List1.AddItem "eee"
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.ListIndex = -1
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ItemHeight As Integer
ItemHeight = SendMessage(List1.hWnd, LB_GETITEMHEIGHT, 0, 0)
Y = min(((Y / Screen.TwipsPerPixelY) \ ItemHeight) + List1.TopIndex, List1.ListCount - 1)
Label1.Caption = "Выделен элемент " & Y
List1.ListIndex = Y
End Sub
Function min(X As Integer, Y As Integer) As Integer
If X > Y Then min = Y Else min = X
End Function
|
|