Link to home
Start Free TrialLog in
Avatar of const71
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.mnuTableEntity, 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
ASKER CERTIFIED SOLUTION
Avatar of JR2003
JR2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of const71
const71

ASKER

OK that works alot better, but when i move 1 pixel to the absolute Right and Bottom edges of the ListBox, the X and Y never match with Width and Height values respectively. They seem to be off a bit ... Why is that?

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