Class

# DesktopPreferencesMenuItem

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

## Description

<span class="title-ref">DesktopPreferencesMenuItem</span> is designed to handle the Preferences menu item for macOS applications. A menu item derived from the <span class="title-ref">DesktopPreferencesMenuItem</span> class is automatically moved to the application menu under macOS. Under other operating systems, such a menu item stays where you put it in the Menu Editor.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                    | Type                               | Read-Only | Shared |
|---------------------------------------------------------|------------------------------------|-----------|--------|
| `AutoEnabled<desktoppreferencesmenuitem.autoenabled>`   | `Boolean</api/data_types/boolean>` |           |        |
| `Enabled<desktoppreferencesmenuitem.enabled>`           | `Boolean</api/data_types/boolean>` |           |        |
| `HasCheckMark<desktoppreferencesmenuitem.hascheckmark>` | `Boolean</api/data_types/boolean>` |           |        |
| `Icon<desktoppreferencesmenuitem.icon>`                 | `Picture</api/graphics/picture>`   |           |        |
| `Index<desktoppreferencesmenuitem.index>`               | `Integer</api/data_types/integer>` | ✓         |        |
| `LastRowIndex<desktoppreferencesmenuitem.lastrowindex>` | `Integer</api/data_types/integer>` | ✓         |        |
| `Name<desktoppreferencesmenuitem.name>`                 | `String</api/data_types/string>`   |           |        |
| `Shortcut<desktoppreferencesmenuitem.shortcut>`         | `String</api/data_types/string>`   |           |        |
| `Tag<desktoppreferencesmenuitem.tag>`                   | `Variant</api/data_types/variant>` |           |        |
| `Text<desktoppreferencesmenuitem.text>`                 | `String</api/data_types/string>`   |           |        |
| `Visible<desktoppreferencesmenuitem.visible>`           | `Boolean</api/data_types/boolean>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                    | Parameters                                                                                                          | Returns                                                        | Shared |
|---------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|--------|
| `AddMenu<desktoppreferencesmenuitem.addmenu>`           | Item As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`                                              |                                                                |        |
| `AddMenuAt<desktoppreferencesmenuitem.addmenuat>`       | Index As `Integer</api/data_types/integer>`, Item As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` |                                                                |        |
| `Child<desktoppreferencesmenuitem.child>`               | Name As `String</api/data_types/string>`                                                                            | `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` |        |
| `Clone<desktoppreferencesmenuitem.clone>`               |                                                                                                                     | `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` |        |
| `Close<desktoppreferencesmenuitem.close>`               |                                                                                                                     |                                                                |        |
| `Constructor<desktoppreferencesmenuitem.constructor0>`  | Text As `String</api/data_types/string>`, \[Tag As `Variant</api/data_types/variant>`\]                             |                                                                |        |
| `Count<desktoppreferencesmenuitem.count>`               |                                                                                                                     | `Integer</api/data_types/integer>`                             |        |
| `Handle<desktoppreferencesmenuitem.handle>`             |                                                                                                                     | `Ptr</api/data_types/additional_types/ptr>`                    |        |
|                                                         | type As `HandleTypes<desktopmenuitem.handletypes>`                                                                  | `Ptr</api/data_types/additional_types/ptr>`                    |        |
| `MenuAt<desktoppreferencesmenuitem.menuat>`             | Index As `Integer</api/data_types/integer>`                                                                         | `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` |        |
| `PopUp<desktoppreferencesmenuitem.popup>`               | \[x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`\]                                | `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` |        |
| `RemoveMenuAt<desktoppreferencesmenuitem.removemenuat>` | Index As `Integer</api/data_types/integer>`                                                                         |                                                                |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                            | Parameters | Returns                            |
|-----------------------------------------------------------------|------------|------------------------------------|
| `MenuBarSelected<desktoppreferencesmenuitem.menubarselected>`   |            |                                    |
| `MenuItemSelected<desktoppreferencesmenuitem.menuitemselected>` |            | `Boolean</api/data_types/boolean>` |

## Property descriptions

<div id="desktoppreferencesmenuitem.autoenabled">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.AutoEnabled

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

> If set to `True</api/language/true>`, the **DesktopMenuItem** 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 `MenuBarSelected<desktopmenuitem.menubarselected>` 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 **DesktopMenuItem**, AutoEnabled is also `True</api/language/true>` by default. See the example on dynamic menus on the `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` page.

<div id="desktoppreferencesmenuitem.enabled">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.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</api/language/true>` in the MenuBarSelected event handler.
>
> You can set it for MenuItems created for use by `contextual menus<desktopuicontrol.constructcontextualmenu>` or for use with the `Popup<desktopmenuitem.popup>` method.
>
> This example is in the MenuBarSelected event handler and it enables a menu.
>
> ``` xojo
> FilePageSetup.Enabled = True
> ```

<div id="desktoppreferencesmenuitem.hascheckmark">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.HasCheckMark

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

> Indicates whether or not the menu item is checked.

<div id="desktoppreferencesmenuitem.icon">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Icon

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

> A picture that is assigned to the **DesktopMenuItem**.
>
> 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):
>
> ``` plain
> gsettings set org.gnome.desktop.interface menus-have-icons true
> ```
>
> The following code is in the `Opening<desktopwindow.opening>` event of the main window. The image appears to the left of the menu item's text.
>
> ``` xojo
> EditFind.Icon = RedApple
> ```

<div id="desktoppreferencesmenuitem.index">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.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="desktoppreferencesmenuitem.lastrowindex">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.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="desktoppreferencesmenuitem.name">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.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.MenuAt(2).Name = "Delete"
> ```

<div id="desktoppreferencesmenuitem.shortcut">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Shortcut

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

> The keyboard shortcut for the **DesktopMenuItem**.
>
> 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`.

<div id="desktoppreferencesmenuitem.tag">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.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 `DesktopPopupMenu</api/user_interface/desktop/desktoppopupmenu>` control.
>
> This example is in the Opening event of the main window.
>
> ``` xojo
> EditFind.Tag = "Search"
> ```

<div id="desktoppreferencesmenuitem.text">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Text

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

> The value (text) of the menu item.
>
> This example is in the Opening event of the main window.
>
> ``` xojo
> EditFind.Text = "Find..."
> ```

<div id="desktoppreferencesmenuitem.visible">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.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 `DesktopMenuItem<desktopmenuitem.removemenuat>` instead.
>
> This code is in the Opening event of the main window:
>
> ``` xojo
> EditFind.Visible = False
> ```

## Method descriptions

<div id="desktoppreferencesmenuitem.addmenu">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.AddMenu

**AddMenu**(Item As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`)

> Adds the passed DesktopMenuItem to the menu. You can add a Separator by passing the class constant DesktopMenuItem.TextSeparator. Used to build a dynamic menu.
>
> The following code creates a contextual menu in the ConstructContextualMenu event of any `DesktopWindow</api/user_interface/desktop/desktopwindow>` or `DesktopUIControl</api/user_interface/desktop/desktopuicontrol>`. This event passes in the parameter base as DesktopMenuItem.
>
> ``` xojo
> base.AddMenu(New DesktopMenuItem("Import"))
> base.AddMenu(New DesktopMenuItem("Export"))
> base.AddMenu(New DesktopMenuItem(DesktopMenuItem.TextSeparator))
>
> base.AddMenu(New DesktopMenuItem("Cut"))
> base.AddMenu(New DesktopMenuItem("Copy"))
> base.AddMenu(New DesktopMenuItem("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 Opening event of the App or the window. It's easiest to create menus and menuitems using the built-in Menu Editor and enable the DesktopMenuItems using the AutoEnable property. Use code for cases such as dynamic menus and contextual menus.
>
> ``` xojo
> Var m, mNew As DesktopMenuItem
> m = Self.MenuBar
> mNew = New DesktopMenuItem
>
> mNew.Text = "View"
> mNew.Name = "View"
>
> mNew.AddMenu(New DesktopMenuItem("As Icons"))
> mNew.AddMenu(New DesktopMenuItem("As List"))
> mNew.AddMenu(New DesktopMenuItem("As Columns"))
>
> mNew.AddMenu(New DesktopMenuItem( "-" ))
>
> Var submenu As New DesktopMenuItem("Sort By")
> submenu.AddMenu(New DesktopMenuItem("Name"))
> submenu.AddMenu(New DesktopMenuItem("Kind"))
> submenu.AddMenu(New DesktopMenuItem("Size"))
>
> mNew.AddMenu(submenu) 
> m.AddMenu(mNew)
> ```

<div id="desktoppreferencesmenuitem.addmenuat">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.AddMenuAt

**AddMenuAt**(Index As `Integer</api/data_types/integer>`, Item As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`)

> Adds *Item* as a DesktopMenuItem at the position indicated by *Index*. Index is zero-based.
>
> You can add a Separator by passing the class constant DesktopMenuItem.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 DesktopMenuItem
> editPasteSpecial.Text = "Paste Special..."
> EditMenu.AddMenuAt(5, editPasteSpecial)
> ```

<div id="desktoppreferencesmenuitem.child">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Child

**Child**(Name As `String</api/data_types/string>`) As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`

> Looks up menu items by Name and returns a DesktopMenuItem. 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 DesktopMenuItem
> c = EditMenu.Child("EditCut")
> MessageBox(c.Text)
> ```

<div id="desktoppreferencesmenuitem.clone">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Clone

**Clone** As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`

> Makes a copy of the `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` and its `children<desktopmenuitem.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 `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` in different places, use the Clone method to create a new copy of the `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` and its children, if any.
>
> ``` xojo
> Var mi As New DesktopMenuItem("My menu item")
> Var myClone As DesktopMenuItem
>
> myClone = mi.Clone ' Creates an independent copy of "mi"
> ```

<div id="desktoppreferencesmenuitem.close">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Close

**Close**

> Removes dynamically created menu items.
>
> This example closes a menu item that was previously created.
>
> ``` xojo
> EditSelectAll.Close
> ```

<div id="desktoppreferencesmenuitem.constructor0">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Constructor

**Constructor**(Text As `String</api/data_types/string>`, \[Tag As `Variant</api/data_types/variant>`\])

> <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 DesktopMenuItem 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 DesktopMenuItem
> editPasteSpecial.Text = "Paste Special..."
> EditMenu.AddMenuAt(5, editPasteSpecial)
> ```
>
> Using this constructor, you can rewrite the code above more concisely:
>
> ``` xojo
> Var editPasteSpecial As New DesktopMenuItem("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 Opening even of a window it will add a new menu to menubar when the window opens.
>
> ``` xojo
> Var m As DesktopMenuItem
> Var mNew As DesktopMenuItem
>
> m = Self.MenuBar
> mNew = New DesktopMenuItem
>
> mNew.Text = "MyMenuText"
> mNew.Name = "MyMenuName"
>
> Var submenu As New DesktopMenuItem("MySub")
>
> submenu.AddMenu(New DesktopMenuItem("Submenu One"))
> submenu.AddMenu(New DesktopMenuItem("Submenu Two"))
> submenu.AddMenu(New DesktopMenuItem("Submenu three"))
>
> mNew.AddMenu(submenu)
>
> m.AddMenu(mNew)
> ```

<div id="desktoppreferencesmenuitem.count">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.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="desktoppreferencesmenuitem.handle">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

> Provides access to the appropriate underlying Linux or macOS menu implementation.

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

**Handle**(type As `HandleTypes<desktopmenuitem.handletypes>`) As `Ptr</api/data_types/additional_types/ptr>`

> Provides access to the appropriate underlying Windows OS menu implementation.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> Passing a type as a parameter to this method on Linux or macOS will result in a `PlatformNotSupportedException</api/exceptions/platformnotsupportedexception>` .
>
> </div>

<div id="desktoppreferencesmenuitem.menuat">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.MenuAt

**MenuAt**(Index As `Integer</api/data_types/integer>`) As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`

> Item returns as a DesktopMenuItem the item indicated by the index passed.
>
> If the passed index is out of range, an `OutOfBoundsException</api/exceptions/outofboundsexception>` is raised.
>
> The following example gets the DesktopMenuItem corresponding to the Cut item on the Edit menu by position:
>
> ``` xojo
> Var c As DesktopMenuItem
> c = EditMenu.MenuAt(2)
> MessageBox(c.Text)
> ```

<div id="desktoppreferencesmenuitem.popup">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.PopUp

**PopUp**(\[x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`\]) As `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`

> Displays the DesktopMenuItem 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 **DesktopMenuItem**. 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 `DesktopUIControl</api/user_interface/desktop/desktopuicontrol>`. You can get the text of the selected item by accessing the Text property of the returned DesktopMenuItem.
>
> ``` xojo
> Var popMenu As DesktopMenuItem
> popMenu = EditMenu.Clone
>
> Var selectedMenu As DesktopMenuItem
> selectedMenu = popMenu.Popup
> ```

<div id="desktoppreferencesmenuitem.removemenuat">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.RemoveMenuAt

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

> Removes the DesktopMenuItem 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="desktoppreferencesmenuitem.menubarselected">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.MenuBarSelected

**MenuBarSelected**

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

<div id="desktoppreferencesmenuitem.menuitemselected">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopPreferencesMenuItem.MenuItemSelected

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

> Called when a DesktopMenuItem 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 `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` page for an example of how a menu that is created dynamically can use the `MenuItemSelected<desktopmenuitem.menuitemselected>` event.

## Notes

Since this class is based on `DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>`, please refer to this class for information on its Properties, Methods, and Events.

This class is for creating the Preferences menu item for applications that will run on macOS. Create the menu item under the menu that you want to use for the Windows and Linux builds and then use the Inspector to change its super class to <span class="title-ref">DesktopPreferencesMenuItem</span>. Otherwise, set up the menu item normally. In your macOS build, it will automatically move to the application menu.

According to Apple user interface guidelines, `Cmd + ,` (comma) is the recommended keyboard shortcut for an application's Preferences menu item.

## Compatibility

|                       |         |
|-----------------------|---------|
| **Project Types**     | Desktop |
| **Operating Systems** | All     |

<div class="seealso">

`DesktopMenuItem</api/user_interface/desktop/desktopmenuitem>` parent class; `DesktopApplicationMenuItem</api/user_interface/desktop/desktopapplicationmenuitem>`, `DesktopQuitMenuItem</api/user_interface/desktop/desktopquitmenuitem>` classes.

</div>
