B4J Question Contextmenu passes mouse right click and activates button being clicked on.

Tim Chapman

Active Member
Licensed User
Longtime User
I am using the contextmenu here:

When I right click on a button to bring up the context menu, the button is activated.
I have found that this is the case only when the sub that catches the normal button click is like this:
Private Sub btnExampleButton_MouseClicked(EventData As MouseEvent).
If the envent handleer is changed to Private Sub btnExampleButton_Click, then the problem goes away.
This prevents the EventData as MouseEvent from being available in the sub that handles the mouse click which can also be a problem.
Is there a better way to fix this problem?

See here for more details:
 
Last edited:
Solution
A simple solution is to check whether it is the secondary button:
B4X:
Private Sub Button1_MouseClicked(EventData As MouseEvent) 
    If EventData.SecondaryButtonPressed Then Return
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

I saw your comment in the code but I'm not sure that I understand it.

Tim Chapman

Active Member
Licensed User
Longtime User
Can you create a small project with this code?
Hi Erel,
It is attached.
Change line 69. _Clicked won't allow the right click to pass to the button. _MouseClicked(EventData As MouseEvent) will. Please let me know if I can be of further assistance.
 

Attachments

  • ContextMenu.zip
    2.9 KB · Views: 15
Upvote 0

Tim Chapman

Active Member
Licensed User
Longtime User
My comment was to say that if you use Button1_MouseClicked(EventData As MouseEvent) , then the right click will pass through and activate the button.
If you use Button1_Click, then it won't. This doesn't allow the EventData to be usable.

Your answer is great because it allows the EventData to be usable as well as the right click.
 
Upvote 0
Top