Solved

Mouse Up Event with Right-Click PopUp Menu

Posted on 2004-08-29
2
190 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now