3.11 Context menus

In MUI GUIs every gadget can have its own context menu that is automatically popped up whenever the mouse pointer is over the gadget and the user holds down the right mouse button. Context menus are assigned to the different gadgets by using the Area.ContextMenu attribute. As Area class is the super-class for all MUI gadgets, you can use this attribute with every MUI object that has a visual representation in form of a gadget.

Area.ContextMenu expects a MUI menustrip object as its argument so you have to create a menustrip for your context menu in XML first. It is very important to note that you have to declare your menustrips in the <application> scope because menustrips are global objects and are only attached to windows or gadgets later on. That is why it is not allowed to declare menustrips inside a <window> XML scope.

Here is an example in which we add a cut, copy, and paste context menu to an object of type Texteditor class:

 
<menustrip id="ctxtmenu">
   <menu title="Context menu">
      <item>Cut</item>
      <item>Copy</item>
      <item>Paste</item>
   </menu>
</menustrip>

<window>
...
   <texteditor contextmenu="ctxtmenu"/>
...
</window>

Please note that menustrips which are used as context menus must not contain more than one <menu> tree.


Show TOC