Solved

Mouse Up Event with Right-Click PopUp Menu

Posted on 2004-08-29
2
192 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:const71
2 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 500 total points
ID: 11927781
I think your 'If' statement is slightly wrong. Try this.

Private Sub TableData_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

    With TableData
        If (Button = vbRightButton) Then
            If (X >= 0) And (X <= .Width) And (Y >= 0) And (Y <= .Height) Then
                MsgBox "hello " & X & "  " & Y
            End If
        End If
    End With

End Sub
0
 

Author Comment

by:const71
ID: 11927837
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
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question