const71
asked on
Mouse Up Event with Right-Click PopUp Menu
I want to be able to register a Right-Click Mouse Press by the user when they click within a ListBox. I want to code this in the Mouse Up event as other Windows programs do, however there seems to be a problem .... When i initiate the click (MouseDown) it is indeed within the ListBox, however when I move the mouse outside the ListBox, the MouseUp event gets called and so it brings up my Context-Sensitive Menu.
I also tried ranging within the MouseUp event like so
LIST BOX MOUSE UP EVENT:
Private Sub TableData_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = vbRightButton) Then
If (X >= TableData.Left And X <= TableData.Left + TableData.Width And Y >= TableData.Top) Then
Call PopupMenu(frmWorkspace.mnu TableEntit y, vbPopupMenuRightAlign)
End If
End If
End Sub
but this does NOT work as I planned. The X and Y parameter dont seem to work with the LEFT, TOP WIDTH and HEIGHT.
What is the proper way to code Right-Click PopUpMenu events for ListBox so the registered last click is exactly within the ListBox??
Thanks
I also tried ranging within the MouseUp event like so
LIST BOX MOUSE UP EVENT:
Private Sub TableData_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = vbRightButton) Then
If (X >= TableData.Left And X <= TableData.Left + TableData.Width And Y >= TableData.Top) Then
Call PopupMenu(frmWorkspace.mnu
End If
End If
End Sub
but this does NOT work as I planned. The X and Y parameter dont seem to work with the LEFT, TOP WIDTH and HEIGHT.
What is the proper way to code Right-Click PopUpMenu events for ListBox so the registered last click is exactly within the ListBox??
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Private Sub TableData_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "[" & X & "] = X [" & TableData.Width & "] = WIDTH"
Debug.Print "[" & Y & "] = Y [" & TableData.Height & "] = HEIGHT"
With TableData
If (Button = vbRightButton) Then
If (X >= 0) And (X <= .Width) And (Y >= 0) And (Y <= .Height) Then
Debug.Print "INSIDE"
End If
End If
End With
End Sub