<div class="meta" robots="noindex">

</div>

Class

# ApplicationMenuItem

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2021r3. Please use `DesktopApplicationMenuItem</api/user_interface/desktop/desktopapplicationmenuitem>` as a replacement.

</div>

## Description

Used to place menu items in the Application menu on macOS. A menu item subclassed from <span class="title-ref">ApplicationMenuItem</span> is automatically moved to the Application menu for macOS builds. On all other target platforms, the menu item appears where you put it in the Menu Editor. You cannot place menu items directly in the Apple or application menus in the Menu Editor.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                                   | Type                               | Read-Only | Shared |
|------------------------------------------------------------------------|------------------------------------|-----------|--------|
| `AutoEnabled<applicationmenuitem.autoenabled>`                         | `Boolean</api/data_types/boolean>` |           |        |
| `Enabled<applicationmenuitem.enabled>`                                 | `Boolean</api/data_types/boolean>` |           |        |
| `Handle<applicationmenuitem.handle>`                                   | `Integer</api/data_types/integer>` | ✓         |        |
| `HasAltKey<applicationmenuitem.hasaltkey>`                             | `Boolean</api/data_types/boolean>` | ✓         |        |
| `HasCheckmark<applicationmenuitem.hascheckmark>`                       | `Boolean</api/data_types/boolean>` |           |        |
| `HasMacControlKey<applicationmenuitem.hasmaccontrolkey>`               | `Boolean</api/data_types/boolean>` | ✓         |        |
| `HasMacOptionKey<applicationmenuitem.hasmacoptionkey>`                 | `Boolean</api/data_types/boolean>` | ✓         |        |
| `HasSecondaryModifierKey<applicationmenuitem.hassecondarymodifierkey>` | `Boolean</api/data_types/boolean>` | ✓         |        |
| `HasStandardModifierKey<applicationmenuitem.hasstandardmodifierkey>`   | `Boolean</api/data_types/boolean>` | ✓         |        |
| `Icon<applicationmenuitem.icon>`                                       | `Picture</api/graphics/picture>`   |           |        |
| `Index<applicationmenuitem.index>`                                     | `Integer</api/data_types/integer>` | ✓         |        |
| `LastRowIndex<applicationmenuitem.lastrowindex>`                       | `Integer</api/data_types/integer>` | ✓         |        |
| `Name<applicationmenuitem.name>`                                       | `String</api/data_types/string>`   |           |        |
| `Shortcut<applicationmenuitem.shortcut>`                               | `String</api/data_types/string>`   |           |        |
| `ShortcutKey<applicationmenuitem.shortcutkey>`                         | `String</api/data_types/string>`   | ✓         |        |
| `Tag<applicationmenuitem.tag>`                                         | `Variant</api/data_types/variant>` |           |        |
| `Value<applicationmenuitem.value>`                                     | `String</api/data_types/string>`   |           |        |
| `Visible<applicationmenuitem.visible>`                                 | `Boolean</api/data_types/boolean>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                             | Parameters                                                                                                         | Returns                              | Shared |
|--------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|--------------------------------------|--------|
| `AddMenu<applicationmenuitem.addmenu>`           | Item As `MenuItem</api/deprecated/menuitem>`                                                                       |                                      |        |
| `AddMenuAt<applicationmenuitem.addmenuat>`       | Index As `Integer</api/data_types/integer>`, Item As `MenuItem</api/deprecated/menuitem>`                          |                                      |        |
| `Child<applicationmenuitem.child>`               | Name As `String</api/data_types/string>`                                                                           | `MenuItem</api/deprecated/menuitem>` |        |
| `Clone<applicationmenuitem.clone>`               |                                                                                                                    | `MenuItem</api/deprecated/menuitem>` |        |
| `Close<applicationmenuitem.close>`               |                                                                                                                    |                                      |        |
| `Constructor<applicationmenuitem.constructor0>`  | Text As `String</api/data_types/string>`, \[Tag As `Variant</api/data_types/variant>` = `Nil</api/language/nil>`\] |                                      |        |
| `Count<applicationmenuitem.count>`               |                                                                                                                    | `Integer</api/data_types/integer>`   |        |
| `MenuAt<applicationmenuitem.menuat>`             | Index As `Integer</api/data_types/integer>`                                                                        | `MenuItem</api/deprecated/menuitem>` |        |
| `Popup<applicationmenuitem.popup>`               | \[x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`\]                               | `MenuItem</api/deprecated/menuitem>` |        |
| `Remove<applicationmenuitem.remove>`             | Child As `MenuItem</api/deprecated/menuitem>`                                                                      |                                      |        |
| `RemoveMenuAt<applicationmenuitem.removemenuat>` | Index As `Integer</api/data_types/integer>`                                                                        |                                      |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                         | Parameters | Returns                            |
|----------------------------------------------|------------|------------------------------------|
| `Action<applicationmenuitem.action>`         |            | `Boolean</api/data_types/boolean>` |
| `EnableMenu<applicationmenuitem.enablemenu>` |            |                                    |

## Property descriptions

<div id="applicationmenuitem.autoenabled">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.AutoEnabled

**AutoEnabled** As `Boolean</api/data_types/boolean>`

If set to `True</api/language/true>`, the **MenuItem** is enabled by default, as long as the `App</api/language/app>` object or frontmost window has a menu handler for the menuitem.

There is no need to put code in the `EnableMenu<menuitem.enablemenu>` event handler to explicitly enable an autoenabled menu item. AutoEnabled is `True</api/language/true>` by default. When you create dynamic menus by creating a new class based on **MenuItem**, AutoEnabled is also `True</api/language/true>` by default. See the example on dynamic menus on the `MenuItem</api/deprecated/menuitem>` page.

<div id="applicationmenuitem.enabled">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Enabled

**Enabled** As `Boolean</api/data_types/boolean>`

Indicates whether or not the menu item is enabled.

For MenuItems that belong to an App or Window menu, this property should only be set to True in the EnableMenuItems event handler.

You can set it for MenuItems created for use by `contextual menus<rectcontrol.constructcontextualmenu>` or for use with the `Popup<menuitem.popup>` method.

This example is in the EnableMenuItems event handler and it enables a menu.

``` xojo
FilePageSetup.Enabled = True
```

<div id="applicationmenuitem.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Handle

**Handle** As `Integer</api/data_types/integer>`

Provides access to the appropriate underlying platform menu implementation.

This property is read-only.

If the requested handle type doesn't make sense for the platform the application is running on, a PlatformNotSupportedException is raised.

**MenuItem.HandleType** enumeration:

- CocoaNSMenuItem: Returns the underlying NSMenuItem. If there is a submenu, the NSMenu can be got through NSMenuItem's submenu method.
- WindowsParentHMENU: Returns the HMENU of the MenuItem if it is a submenu, otherwise it returns the parent's HMENU
- WindowsCommandID: Returns the unique menu item identifier for the MenuItem, used by various Win32 APIs such as GetMenuItemInfo

<div id="applicationmenuitem.hasaltkey">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.HasAltKey

**HasAltKey** As `Boolean</api/data_types/boolean>`

The Alt key on Windows and Linux keyboards. If selected, the Alt key is must be held down while pressing the value of the Key property in order to trigger the event handler for the `MenuItem</api/deprecated/menuitem>`. This property is for Windows and Linux only.

This property is read-only.

Use `MenuItem<menuitem.shortcut>` to change this value at runtime.

<div id="applicationmenuitem.hascheckmark">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.HasCheckmark

**HasCheckmark** As `Boolean</api/data_types/boolean>`

Indicates whether or not the menu item is checked.

<div id="applicationmenuitem.hasmaccontrolkey">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.HasMacControlKey

**HasMacControlKey** As `Boolean</api/data_types/boolean>`

The Control key on Mac. This property is Mac-only. If selected, the Control key must be held down while pressing the value of the `ShortcutKey<menuitem.shortcutkey>` property in order to trigger the event handler of the `MenuItem</api/deprecated/menuitem>`.

This property is read-only.

Use `MenuItem<menuitem.shortcut>` to change this value at runtime.

<div id="applicationmenuitem.hasmacoptionkey">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.HasMacOptionKey

**HasMacOptionKey** As `Boolean</api/data_types/boolean>`

The Option key on Mac. This property is Mac-only. If selected, the Option key must be held down while pressing the value of the `ShortcutKey<menuitem.shortcutkey>` property to trigger the event handler of the `MenuItem</api/deprecated/menuitem>`.

This property is read-only.

Use `MenuItem<menuitem.shortcut>` to change this value at runtime.

<div id="applicationmenuitem.hassecondarymodifierkey">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.HasSecondaryModifierKey

**HasSecondaryModifierKey** As `Boolean</api/data_types/boolean>`

The Shift key on all platforms. If `True</api/language/true>`, the Shift key must be held down while pressing the value of the Key property to trigger the event handler of the `MenuItem</api/deprecated/menuitem>`.

This property is read-only.

Use `MenuItem<menuitem.shortcut>` to change this value at runtime.

<div id="applicationmenuitem.hasstandardmodifierkey">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.HasStandardModifierKey

**HasStandardModifierKey** As `Boolean</api/data_types/boolean>`

The Control key on Windows and Linux and the Command key on Mac. If this property is selected, the MenuModifier key must be held down while pressing the key specified by the `ShortcutKey<menuitem.shortcutkey>` property to trigger the event handler for the `MenuItem</api/deprecated/menuitem>`.

This property is read-only.

Use `MenuItem<menuitem.shortcut>` to change this value at runtime.

<div id="applicationmenuitem.icon">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Icon

**Icon** As `Picture</api/graphics/picture>`

A picture that is assigned to the **MenuItem**.

On macOS and Linux, the picture appears in its original size. Resize the icon externally before adding it to the project. On Windows, the icon is resized so that its size matches the height of the item's Text. In most cases icons that are 16x16 points look best.

Recent versions of Linux (that use recent version of the GNOME desktop manager), default to not showing menu icons. You can change the OS setting to display menu icons using terminal [](http://gnomeshell.wordpress.com/2011/09/11/show-and-hide-the-menu-icons/):

> gsettings set org.gnome.desktop.interface menus-have-icons true

The following code is in the `Open<window.open>` event of the main window. The image appears to the left of the menu item's text.

``` xojo
EditFind.Icon = RedApple
```

<div id="applicationmenuitem.index">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Index

**Index** As `Integer</api/data_types/integer>`

The number of the selected MenuItem when it is part of an array.

This property is read-only.

<div id="applicationmenuitem.lastrowindex">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.LastRowIndex

**LastRowIndex** As `Integer</api/data_types/integer>`

The index of the last child menu item owned by this menu.

This property is read-only.

<div id="applicationmenuitem.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Name

**Name** As `String</api/data_types/string>`

The name of the menu item. Set this property using the Menu Editor.

This example sets the name of a menuitem.

``` xojo
EditMenu.Item(2).Name = "Delete"
```

<div id="applicationmenuitem.shortcut">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Shortcut

**Shortcut** As `String</api/data_types/string>`

The keyboard shortcut for the **MenuItem**.

Use this property to set the shortcut in code. You can also specify a shortcut in the Inspector for the MenuItem.

You can use either a printable key or the following non-printable keys as shortcut keys: F1-F15, Tab, Enter, Space, Del (Delete), Return, Bksp (Backspace), Esc, Clear, PageUp, PageDown, Left, Right, Up, Down, Help, and Ins (Insert).

If the shortcut key is more than one character and it is being set via code, the modifier key is not implied and must be explicitly defined. For example, the following line sets the Tab key as the shortcut key and uses the Ctrl key as the modifier.

``` xojo
SpecialMyMenuItem.Shortcut = "Ctrl-Tab"
```

For macOS, use "Cmd" instead of "Ctrl." Or set the `HasStandardModifierKey<menuitem.hasstandardmodifierkey>` property to `True</api/language/true>` in the IDE and pass the string literal for the desired keyboard shortcut.

<div id="applicationmenuitem.shortcutkey">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.ShortcutKey

**ShortcutKey** As `String</api/data_types/string>`

The shortcut key for the menu item. If this key and the selected modifier keys are held down, the event handler for the menu item will be executed as if the `MenuItem</api/deprecated/menuitem>` itself were chosen via the mouse pointer.

This property is read-only.

When you use the Inspector for the Menu Editor, you specify the menu item's shortcut key by assigning a key to the Key property and (normally) at least one modifier key. The Menu Editor translates your settings into the value for the `Shortcut<menuitem.shortcut>` property.

You can use either a printable key or the following non-printable keys as shortcut keys: F1-F15, Tab, Enter, Space, Del (Delete), Return, Bksp (Backspace), Esc, Clear, PageUp, PageDown, Left, Right, Up, Down, Help, and Ins (Insert).

To set the shortcut in code, use the `MenuItem<menuitem.shortcut>` property. If the shortcut key is more than one character and it is being set via code, the modifier key is not implied and must be explicitly defined. For example, the following line sets the Tab key as the shortcut key and uses the Ctrl key as the modifier.

``` xojo
SpecialMyMenuItem.Shortcut = "Ctrl-Tab"
```

For macOS, use "Cmd" instead of "Ctrl." Or set the `HasStandardModifierKey<menuitem.hasstandardmodifierkey>` property to `True</api/language/true>` in the IDE and pass the string literal for the desired keyboard shortcut.

<div id="applicationmenuitem.tag">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Tag

**Tag** As `Variant</api/data_types/variant>`

A “hidden” value associated with the menu item.

The tag is accessible via code when the user chooses the menu item but, unlike the Text property, is not displayed in the menu. It works like the RowTag property of a `PopupMenu</api/deprecated/popupmenu>` control.

This example is in the Open event of the main window.

``` xojo
EditFind.Tag = "Search"
```

<div id="applicationmenuitem.value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Value

**Value** As `String</api/data_types/string>`

The value (text) of the menu item.

This example is in the Open event of the main window.

``` xojo
EditFind.Text = "Find..."
```

<div id="applicationmenuitem.visible">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Visible

**Visible** As `Boolean</api/data_types/boolean>`

Indicates whether or not the menu item is visible. The default is `True</api/language/true>`. If `False</api/language/false>`, the menu item does not appear and no blank space is for it is in the menu.

This property does nothing on Windows so use `MenuItem<menuitem.removemenuat>` instead.

This code is in the Open event of the main window:

``` xojo
EditFind.Visible = False
```

## Method descriptions

<div id="applicationmenuitem.addmenu">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.AddMenu

**AddMenu**(Item As `MenuItem</api/deprecated/menuitem>`)

Adds the passed MenuItem to the menu. You can add a Separator by passing the class constant MenuItem.TextSeparator. Used to build a dynamic menu.

The following code creates a contextual menu in the ConstructContextualMenu event of any `Window</api/deprecated/window>` or `RectControl</api/deprecated/rectcontrol>`. This event passes in the parameter base as MenuItem.

``` xojo
base.AddMenu(New MenuItem("Import"))
base.AddMenu(New MenuItem("Export"))
base.AddMenu(New MenuItem(MenuItem.TextSeparator))

base.AddMenu(New MenuItem("Cut"))
base.AddMenu(New MenuItem("Copy"))
base.AddMenu(New MenuItem("Paste"))
Return True ' display the contextual menu
```

The following code creates a hierarchical menu that is added to the main menubar. It is in the Open event of the App or the window. It's easiest to create menus and menuitems using the built-in Menu Editor and enable the MenuItems using the AutoEnable property. Use code for cases such as dynamic menus and contextual menus.

``` xojo
Var m, mNew As MenuItem
m = Self.MenuBar
mNew = New MenuItem

mNew.Value = "View"
mNew.Name = "View"

mNew.AddMenu(New MenuItem("As Icons"))
mNew.AddMenu(New MenuItem("As List"))
mNew.AddMenu(New MenuItem("As Columns"))

mNew.AddMenu(New MenuItem( "-" ))

Var submenu As New MenuItem("Sort By")
submenu.AddMenu(New MenuItem("Name"))
submenu.AddMenu(New MenuItem("Kind"))
submenu.AddMenu(New MenuItem("Size"))

mNew.AddMenu(submenu) 
m.AddMenu(mNew)
```

<div id="applicationmenuitem.addmenuat">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.AddMenuAt

**AddMenuAt**(Index As `Integer</api/data_types/integer>`, Item As `MenuItem</api/deprecated/menuitem>`)

Adds *Item* as a MenuItem at the position indicated by *Index*. Index is zero-based.

You can add a Separator by passing the class constant MenuItem.TextSeparator.

The following example adds a new item in the Edit menu with the text "Paste Special..." just below the Paste item.

``` xojo
Var editPasteSpecial As New MenuItem
editPasteSpecial.Text = "Paste Special..."
EditMenu.AddMenuAt(5, editPasteSpecial)
```

<div id="applicationmenuitem.child">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Child

**Child**(Name As `String</api/data_types/string>`) As `MenuItem</api/deprecated/menuitem>`

Looks up menu items by Name and returns a MenuItem. Returns `Nil</api/language/nil>` if a child is not found.

The following example gets the text of the Edit \> Cut menuitem.

``` xojo
Var c As MenuItem
c = EditMenu.Child("EditCut")
MessageBox(c.Value)
```

<div id="applicationmenuitem.clone">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Clone

**Clone** As `MenuItem</api/deprecated/menuitem>`

Makes a copy of the `MenuItem</api/deprecated/menuitem>` and its `children<menuitem.child>` if any. Mac does not permit duplicate MenuItems, so you will need to create clones of any MenuItems that are now being used in two or more locations.

Whenever you need to use the same `MenuItem</api/deprecated/menuitem>` in different places, use the Clone method to create a new copy of the `MenuItem</api/deprecated/menuitem>` and its children, if any.

``` xojo
Var mi As New MenuItem("My menu item")
Var myClone As MenuItem

myClone = mi.Clone ' Creates an independent copy of "mi"
```

<div id="applicationmenuitem.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Close

**Close**

Removes dynamically created menu items.

This example closes a menu item that was previously created.

``` xojo
EditSelectAll.Close
```

<div id="applicationmenuitem.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Constructor

**Constructor**(Text as `String</api/data_types/string>`, \[Tag as `Variant</api/data_types/variant>` = `Nil</api/language/nil>`\])

<div class="note">

<div class="title">

Note

</div>

`Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.

</div>

Creates a new MenuItem that uses the passed string as its Text property and optionally adds the passed Tag.

This example inserts a new item in the Edit menu with the text "Paste Special..." just below the Paste item.

``` xojo
Var editPasteSpecial As New MenuItem
editPasteSpecial.Text = "Paste Special..."
EditMenu.AddMenuAt(5, editPasteSpecial)
```

Using this constructor, you can rewrite the code above more concisely:

``` xojo
Var editPasteSpecial As New MenuItem("Paste Special...")
EditMenu.AddMenuAt(5, editPasteSpecial)
```

This example illustrates how you can manipulate the menu bar at run time. By adding this example to the open even of a window it will add a new menu to menubar when the window opens.

``` xojo
Var m As MenuItem
Var mNew As MenuItem

m = Self.MenuBar
mNew = New MenuItem

mNew.Text = "MyMenuText"
mNew.Name = "MyMenuName"

Var submenu As New MenuItem("MySub")

submenu.AddMenu(New MenuItem("Submenu One"))
submenu.AddMenu(New MenuItem("Submenu Two"))
submenu.AddMenu(New MenuItem("Submenu three"))

mNew.AddMenu(submenu)

m.AddMenu(mNew)
```

<div id="applicationmenuitem.count">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Count

**Count** As `Integer</api/data_types/integer>`

Returns as an `Integer</api/data_types/integer>` the number of children a menu owns.

For a menu item, it returns the number of submenu items, if any. If there are no submenu items, it returns zero.

<div id="applicationmenuitem.menuat">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.MenuAt

**MenuAt**(Index As `Integer</api/data_types/integer>`) As `MenuItem</api/deprecated/menuitem>`

Item returns as a MenuItem the item indicated by its index (zero-based).

If the passed index is out of range, an `OutOfBoundsException</api/exceptions/outofboundsexception>` is raised.

The following example gets the MenuItem corresponding to the Cut item on the Edit menu by position:

``` xojo
Var c As MenuItem
c = EditMenu.MenuAt(2)
MessageBox(c.Value)
```

<div id="applicationmenuitem.popup">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Popup

**Popup**(\[x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`\]) As `MenuItem</api/deprecated/menuitem>`

Displays the MenuItem as a contextual menu.

If no parameters are passed, the contextual menu appears at the location of the mouse pointer. If you pass the optional parameters, the contextual menu appears at the passed location. The coordinates are global, not just in the object that handles the MouseDown event.

Popup returns the selected item as a **MenuItem**. The selected item's Action event will be fired. If the selected item is handled by a MenuHandler that returns `True</api/language/true>`, then PopUp will return `Nil</api/language/nil>`.

The following example displays the Edit menu as a contextual menu. The code is in the MouseDown event handler of a `RectControl</api/deprecated/rectcontrol>`. You can get the text of the selected item by accessing the Text property of the returned MenuItem.

``` xojo
Var popMenu As MenuItem
popMenu = EditMenu.Clone

Var selectedMenu As MenuItem
selectedMenu = popMenu.Popup
```

<div id="applicationmenuitem.remove">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Remove

**Remove**(Child As `MenuItem</api/deprecated/menuitem>`)

Removes the MenuItem specified by the *name*.

This code removes the Select All menu item from the Edit menu.

``` xojo
EditMenu.Remove(3)
```

<div id="applicationmenuitem.removemenuat">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.RemoveMenuAt

**RemoveMenuAt**(Index As `Integer</api/data_types/integer>`)

Removes the MenuItem specified by its position (index).

This example removes the Select All menu item from the Edit menu.

``` xojo
EditMenu.RemoveMenuAt(3)
```

## Event descriptions

<div id="applicationmenuitem.action">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.Action

**Action** As `Boolean</api/data_types/boolean>`

Called when a MenuItem is selected. Return `True</api/language/true>` to prevent the menu event from proceeding any further in the chain of menu handlers.

Refer to the `MenuItem</api/deprecated/menuitem>` page for an example of how a menu that is created dynamically can use the Action event.

<div id="applicationmenuitem.enablemenu">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ApplicationMenuItem.EnableMenu

**EnableMenu**

Called when a user selects a menu. You can use this to enable/disable/hide menus based on the context of your app.

## Notes

To use <span class="title-ref">ApplicationMenuItem</span>, create the menu item under the menu that you want to use for the Windows and Linux builds of the application and then use the Inspector to change its super class to <span class="title-ref">ApplicationMenuItem</span>. Otherwise, set up the menu item normally.

## Compatibility

All project types on all supported operating systems.

## See also

`MenuItem</api/deprecated/menuitem>` parent class; `MenuItem</api/deprecated/menuitem>`, `PrefsMenuItem</api/deprecated/prefsmenuitem>`, `QuitMenuItem</api/deprecated/quitmenuitem>` classes.
