A menu item in a menubar or popup menu.

Syntax

[<oRef> =] new Menu(<parent>)

<oRef>

A variable or property—typically of <parent>—in which to store a reference to the newly created Menu object.

<parent>

The parent object—a MenuBar, Popup, or another Menu object—that contains the Menu object.

Properties

The following tables list the properties, events, and methods of the Menu class.

Property

Default

Description

baseClassName

MENU

Identifies the object as an instance of the Menu class.

before

 

The next sibling menu object

checked

false

Whether to display a checkmark next to a menu item.

checkedBitmap

 

An image to represent the mark to appear next to the menu item if checked is true.

className

(MENU)

Identifies the object as an instance of a custom class. When no custom class exists, defaults to baseClassName

enabled

true

Determines if the menu can be selected.

helpFile

 

Help file name

helpId

 

Help index topic or context number for context-sensitive help

id

-1

Supplementary ID number for menu item

name

 

The name of the menu item.

parent

 

The menu item’s immediate container

separator

false

Whether the menu object is a separator instead of a selectable menu item.

shortCut

 

The key combination that fires the onClick event.

statusMessage

 

The message to display on the status bar when the menu item has focus.

text

 

The text of the menu item prompt.

uncheckedBitmap

 

An image to represent the mark to appear next to the menu item if checked is false.

 

Event

Parameters

Description

beforeRelease

 

before an object is released from memory.

onClick

 

After the menu item is chosen.

onHelp

 

When F1 is pressed—overrides context-sensitive help

 

Method

Parameters

Description

release( )

 

Explicitly removes the menu object from memory.

Description

Menu objects represent the individual menu items, or prompts, in a menu system. They can be attached to MenuBar objects, Popup objects, or other Menu objects so that:

When attached to a menubar, they are the top-level menu items, such as the standard File and Edit menus.

Menu items attached to a top-level menu item form the drop-down menu, such as the standard Cut and Paste menu items in the top-level Edit menu.

Menu items attached to a popup comprise the items in the popup.

Any other menu items that have menu items attached to them become cascading menus.

Unless a menu item has other menu items attached (making it a cascading menu), selecting the menu item fires its onClick event. Actions are assigned to each menu item by creating an onClick event handler for the menu object.

The actions for the standard Undo, Cut, Copy, and Paste menu items and the Window menu are handled by assigning the menu items to the menubar’s editUndoMenu, editCutMenu, editCopyMenu, editPasteMenu, and windowMenu properties respectively.

Menu objects are also used as separators in a drop-down or popup menu by setting their separator property to true. In this case, the menu item serves no other purpose and cannot be a cascading menu or have an onClick event handler.

Creating accelerators and pick characters

There are two ways to let the user choose a menu item by using the keyboard (which may be used at the same time):

Assign a key combination to the menu item’s shortCut property. This is sometimes called an accelerator. For example, Ctrl+C is usually used for the Cut menu item. Pressing the accelerator chooses the menu item even if the menu item is not visible.

Specify a pick character in the text prompt of the menu item by preceding it with an ampersand (&). Pick characters work only when the menu item is visible. For top-level items in a menubar, you must press Alt and the pick character to activate the menu. Once the menu system is activated, pressing Alt in combination with the pick character is optional.

Note

Assigning F1 as the shortCut key for a menu item disables the built-in context-sensitive help based on the helpFile and helpId properties. The onClick for the menu item will be called instead. Therefore, if you have a menu item for Help it should not have F1 assigned as its shortCut key unless you want to handle help yourself.