|
-
May 2nd, 2001, 01:31 PM
#1
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.
-
May 2nd, 2001, 02:13 PM
#2
-
May 2nd, 2001, 02:15 PM
#3
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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 2nd, 2001, 02:17 PM
#4
Hyperactive Member
I thought about submitting that approach as a solution, but what happens when you scroll through the list items ???
-
May 2nd, 2001, 02:32 PM
#5
techman - it will still work fine.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 2nd, 2001, 04:13 PM
#6
Hyperactive Member
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 !!
-
May 2nd, 2001, 05:50 PM
#7
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
-
May 2nd, 2001, 09:47 PM
#8
Very Nice Megatron!
Flawless!
Thats a keeper
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|