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

</div>

Class

# MenuBar

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

<div class="warning">

<div class="title">

Warning

</div>

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

</div>

## Description

Used to handle the application's and windows' menu bar.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                 | Type                               | Read-Only | Shared |
|--------------------------------------|------------------------------------|-----------|--------|
| `Handle<menubar.handle>`             | `Integer</api/data_types/integer>` | ✓         |        |
| `LastRowIndex<menubar.lastrowindex>` | `Integer</api/data_types/integer>` | ✓         |        |
| `Name<menubar.name>`                 | `String</api/data_types/string>`   |           |        |
| `Tag<menubar.tag>`                   | `Variant</api/data_types/variant>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

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

## Events

<div class="rst-class">

table-centered_column_4

</div>

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

## Property descriptions

<div id="menubar.handle">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.lastrowindex">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.name">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.tag">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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"
```

## Method descriptions

<div id="menubar.addmenu">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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 <span class="title-ref">MenuBar</span>. 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="menubar.addmenuat">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.child">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.clone">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.close">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.Close

**Close**

Removes dynamically created menu items.

This example closes a menu item that was previously created.

``` xojo
EditSelectAll.Close
```

<div id="menubar.constructor0">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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 <span class="title-ref">MenuBar</span> 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="menubar.count">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.menuat">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.popup">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.remove">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.removemenuat">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.action">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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="menubar.enablemenu">

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

</div>

<div class="rst-class">

forsearch

</div>

MenuBar.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

When you create a new desktop project, a default <span class="title-ref">MenuBar</span> (called MainMenuBar) is added to your project.

You can refer to a <span class="title-ref">MenuBar</span> globally by its name because an "implicit instance" is automatically created for you to use. If you use the global name, then you will get the same <span class="title-ref">MenuBar</span> instance everywhere you use it. If you modify the <span class="title-ref">MenuBar</span> in code, the modification will appear everywhere the <span class="title-ref">MenuBar</span> is used.

If you would rather have separate instances of the <span class="title-ref">MenuBar</span>, you should assign it in code manually in the `Window.Open<window.open>` event:

``` xojo
Self.MenuBar = New MainMenuBar
```

On macOS, if a window does not have a `MenuBar<window.menubar>` specified, then the window uses the <span class="title-ref">MenuBar</span> specified on `Application.MenuBar<application.menubar>`.

On Windows and Linux, if a window does not have a `MenuBar<window.menubar>` specified, then the window will display without a <span class="title-ref">MenuBar</span> even if one is specified in `Application.MenuBar<application.menubar>`.

## Compatibility

All project types on all supported operating systems.

## See also

`MenuItem</api/deprecated/menuitem>` parent class; `MenuItem</api/deprecated/menuitem>`; `Application.MenuBar<application.menubar>` and `Window.MenuBar<window.menubar>` properties.
