|
Выделение элемента в ListBox'е при нажатии на правую клавишу мыши |
|
|
Добавьте на форму элемент ListBox 'Пример 1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_ITEMFROMPOINT = &H1A9
Private Sub Form_Load()
List1.AddItem "11"
List1.AddItem "22"
List1.AddItem "33"
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim indeX As Long
Dim XPosition As Long, YPosition As Long
XPosition = CLng(X / Screen.TwipsPerPixelX)
YPosition = CLng(Y / Screen.TwipsPerPixelY)
indeX = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0, ByVal ((YPosition * 65536) +
XPosition))
If indeX < List1.ListCount Then
List1.Selected(indeX) = True
End If
End Sub
'Пример 2
Private Sub Form_Load()
List1.AddItem "11"
List1.AddItem "22"
List1.AddItem "33"
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim iTemp As Integer
If Button = vbRightButton Then
With List1
iTemp = ((Y / Screen.TwipsPerPixelY) \ (TextHeight("A") /
Screen.TwipsPerPixelY)) + .TopIndex
If iTemp > .ListCount - 1 Then iTemp = -1
.ListIndex = iTemp
.SetFocus
End With
End If
End Sub
|
|
|
|
|
|
|