B4J Question Designer ContextMenu

Guenter Becker

Active Member
Licensed User
Hello,
Im new to B4J. In the Designer I add a context menu with 3 items to a button.
Can anyone help me with a B4J snipped how to get the click event if a menu item is selected? Button_click will not work on right mouse click.
I think a way is to use Mouse_Click Event and to look if the right mouse button was clicked but how?
Next if that is solved is how to intercept the selecteditem click?

Thank you in advance
 

aeric

Expert
Licensed User
Longtime User
Check this tutorial
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Sorry aeric but this tutorial deals with the Menubar but I am using a simple button.
I tried without success:
dim ctx as ContextMenu = button1.ContextMenu

Private Sub ctx_Action
    dim Mi as MenuItem = sender
    log(Mi.text)
end sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I am not sure I do this correctly but it works for me.

B4X:
Dim ctx As ContextMenu
ctx.Initialize("ctx")
Dim m1 As MenuItem
m1.Initialize("Item 1", "ctx")
Dim m2 As MenuItem
m2.Initialize("Item 2", "ctx")
Dim m3 As MenuItem
m3.Initialize("Item 3", "ctx")
ctx.MenuItems.AddAll(Array(m1, m2, m3))
Button1.ContextMenu = ctx
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You've created the menu in the designer, is that right?

As the context menu is attached to the button the Sub Signature should be:
B4X:
Private Sub Button1_Action
    Dim MI As MenuItem = Sender
    Log(MI.Text)
    
End Sub
 
Upvote 1
Top