How to enable right click contextual menu in textarea?

I am trying to enable windows default right click contextual menu in textarea, just like in right click in textfield, but cannot found a way after various searching.

How to do it?, i only need default windows one which are having Copy, Paste, select all,etc.

Implement ConstructContextualMenu & ContextualMenuAction

There are no settings for the inspector to do it automatically?

I need to implement it by myself?

Found the solution after search through forums!,

Here it is, probably will be useful to others :

Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) Handles ConstructContextualMenu as Boolean
  base.AddMenu(New MenuItem("Copy"))
  base.AddMenu(New MenuItem("Cut"))
  base.AddMenu(New MenuItem("Paste"))
  base.AddMenu(New MenuItem("Delete"))
  base.AddMenu(New MenuItem("Select All"))
End Function
Function ContextualMenuAction(hitItem as MenuItem) Handles ContextualMenuAction as Boolean
  Dim clippy As new Clipboard
  Select Case hititem.Text
  Case "Copy"
    clippy.text = Me.SelectedText.ToText
  Case "Cut"
    if me.sellength=0 then return true
    dim t as string, i, curPos as integer
    me.copy
    curPos=me.selstart
    for i=0 to me.selstart
      t=t+mid(me.text, i,1)
    next i
    for i=me.selstart+me.SelLength+1 to len(me.text)
      t=t+mid(me.text, i, 1)
      if i>len(me.text) then exit for
    next i
    me.text=t
    me.selstart=curPos
    me.selLength=0
  Case "Paste"
    Me.Paste
  Case "Delete"
    if me.sellength=0 then return true
    dim t as string, i, curPos as integer
    curPos=me.selstart
    for i=0 to me.selstart
      t=t+mid(me.text, i,1)
    next i
    for i=me.selstart+me.SelLength+1 to len(me.text)
      t=t+mid(me.text, i, 1)
      if i>len(me.text) then exit for
    next i
    me.text=t
    me.selstart=curPos
    me.selLength=0
  Case "Select All"
    me.selstart=0
    me.SelLength=me.text.Len
  End Select
  
  Return True
End Function

Or read the docs (Internet) / Language Reference ([LOCAL].

Or in your Xojo folder see Example Projects --> Desktop --> Menus --> ConstructContextualMenu.xojo_binary_project.

The only problem with implementing:

#If TargetWindows Then
  
  WOComments.SetFocus
  
  If IsContextualClick Then
    Var m As MenuItem
    m = EditMenu.Clone.PopUp
  End If
  
#EndIf

The normal context menu for Spell Checking doesn’t occur. Only the EditMenu.Clone.PopUp shows.

How do I have both Cut/Copy/Paste and the Spell Check options appear in one PupUp for a TextArea?

To do what automatically? How can it know what you want in any particular contextual menu.

lol, the normal contextual menu expected for a Text control, like one in TextField :roll_eyes: He already aswer, Xojo has not the standard contextual menu in the Text Area, so it has to be added manually.

It forces a limitation but you could do something like this in the ConstructContextualMenu event

If Me.SelectedText.Length > 0 Then
  Var m As MenuItem
  m = EditMenu.Clone.PopUp
  Return True
End If

Return False

This doesn’t really show both in the same menu but will show the Editmenu clone if there is text selected in the TextArea and the spell checker if there is no text selected (assuming the cursor is in a misspelled word).

So Paste won’t appear when no selection is made.
I don’t think there’s an ideal solution, other than getting the handle of the menu and inserting items (I don’t remember right now whether Xojo provides the handle, though).

That’s true but if there is anything to Paste, the keyboard shortcut still works. I agree that it’s not a great solution.

True, as the shortcuts come from the Edit menu, which stays there (so the Copy and Cut shortcuts always work as well).
The real problem is only the lack of a customisable contextual menu.