B4J Question Trapping a context menu event in Textarea

Rattigan_Roger

Member
Licensed User
I sometimes miss the obvious, so apologies in advance if the answer is thus.

Using the internal WYSIWYG Visual Designer I implemented a Context menu.
The menu properly appears with a right click mouse.

The problem is that the the only way I can find to trap the event is in an Action sub.
However, a TextArea does not appear to have an Action event.
A Mouse event crashes when I try to get event info (Dim mi As MenuItem = Sender)
So, what am I missing?
..... and yes I fear it is obvious.

Thanks in advance for Your time and trouble.
 

Rattigan_Roger

Member
Licensed User
Well I did not get any answers to implement a context menu in a TextArea in a standard way but I did manage a workaround,
Had this been anything other than a personal program used to keep my company and personal finances and tax info it might have been disastorous.
My workaround was using a Listview that positions itself conveniently upon a right mouse click.
Not ideal, but given that B4J is free, I have no real complaints.
 

Daestrum

Well-Known Member
Licensed User
Simple example of ContextMenu inside a TextArea
B4X:
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
 MainForm.Show
 Dim ta As TextArea
 Dim cm As ContextMenu
 ta.Initialize("ta")
 cm.Initialize("")
 Dim mi As MenuItem
 mi.Initialize("open","open")
 cm.MenuItems.Add(mi)
 mi.Initialize("close","close")
 cm.MenuItems.Add(mi)
 ta.ContextMenu = cm
 MainForm.RootPane.AddNode(ta,10,10,200,200)
End Sub
Sub open_Action
 Log("open clicked")
End Sub
Sub close_Action
 Log("close clicked")
End Sub
 
Top