-
Listboxes
Hi. When a user right clicks a listbox, a popup menu appears. To make the menu appear I use the following command
Code:
Private Sub AutoExecEnabled_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
PopupMenu mnuMenuOne
End If
End Sub
If I left click the listbox, the entry that the mouse is over becomes selected. I would like the same to happen when the right mouse button is clicked, before the menu appears, but currently, the entry that the mouse is over only becomes selected when the left mouse button is clicked, not if either button is clicked.
Thanks for any info on accomplishing the task would be appreciated.
-
-
This is Not 100% acurate...but its darn close
it catches about 85 - 90% of the right clicks
Code:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim YPos As Integer, iOldFontSize As Integer
iOldFontSize = Me.Font.Size
Me.Font.Size = List1.Font.Size
YPos = Y / Me.TextHeight("Xyz") + List1.TopIndex
Me.Font.Size = iOldFontSize
If YPos < List1.ListCount Then
If Button = 2 Then
List1.Selected(YPos) = True
PopupMenu mnuMenuOne
End If
End If
End Sub
VBBrowser v2.2.4
-
I thought about submitting that approach as a solution, but what happens when you scroll through the list items ???
-
techman - it will still work fine.
-
Sorry, I didn't see the TopIndex offset....Actually I didn't even realize that there was a TopIndex property !! (I use ListView much more then ListBox)
Thanks !!
-
Or use the LBITemFromPt API function.
Code:
Private Declare Function LBItemFromPt Lib "comctl32.dll" (ByVal hLB As Long, ByVal ptx As Integer, ByVal pty As Integer, ByVal bAutoScroll As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim nPos As Integer
Dim PT As POINTAPI
If Button = 2 Then
GetCursorPos PT
List1.Selected(LBItemFromPt(List1.hwnd, PT.X, PT.Y, 0)) = True
PopupMenu mnu
End If
End Sub
-
Very Nice Megatron!
Flawless!
Thats a keeper