McBasic™Get McBasic™ ↗
Build 881
Components · Nonvisual component
MenuItem component icon

MenuItem

Rebuild a Classic application with Menu Editor actions, runtime control arrays, control dragging, Type value copies, class initialization and Sub Main.

9 properties1 events0 methodsDefault: Click

Use it in a Form#

Create the layout below first. In Design → Menu Editor, add Actions as a title; indent Show details and Clear status underneath it. Name them mnuActions, mnuDetails and mnuClear; set Show details Checked True and Shortcut Ctrl+D. Parent values in the JSON are item IDs, not BASIC names. Give txtCell Index 0 and Dock None: it is the design-time template. DragMode 1 on lblToken is the automatic control-drag source; pnlDrop uses the Source As Control overload, not DragData. Project Settings selects Classic; Startup Object selects Sub Main. Add modStart, SessionCounter and WorkbenchTests before replacing their full source files below. The Boolean mLoaded prevents duplicate Load and missing Unload. Only the newly loaded member is removed; the original template remains. The record test distinguishes copied values (79) from shared identity, while two class instances keep separate counters.

Add MenuItem to the component tray and name it mnuActions for this example:

PropertyExample value
Caption"&Actions"
Order0

Use the full lesson for the owner’s initialization code and its complete layout.

Properties#

Contract defaults are shown below. Where a new control has a different Designer starting value, that value is listed separately.

Caption

StringDefault: ""

Text of the item. & marks the access key that Windows underlines; macOS hides it, and && shows one &. A Caption of - (one hyphen) makes a separator line.

Shortcut

StringDefault: "None"Read only in BASIC

Key combination that chooses the item while its form is active: None, Ctrl+A to Ctrl+Z, F1 to F12, Ctrl+F1, Shift+F1 or Shift+Ctrl+F1 to F12, Ctrl+Ins, Shift+Ins, Del, Shift+Del or Alt+Bksp. On macOS Ctrl is the Command key. A menu title and a separator have none. Read-only in code.

Checked

BooleanDefault: False

Shows a check mark beside the item. Choosing the item does not change it; set it in the Click handler.

Enabled

BooleanDefault: True

Whether the item can be chosen. False greys the item and every item under it; their Click and Shortcut do nothing.

Visible

BooleanDefault: True

Whether the item is shown. False hides the item and every item under it. A hidden menu title still opens with PopupMenu.

WindowList

BooleanDefault: FalseRead only in BASIC

On a menu title, lists the open windows (the child forms of an MDIForm) after the title's own items. At most one title per form. Read-only in code.

Parent

StringDefault: ""Not in InspectorDesigner only

The id of the menu item this item sits under; empty for a menu title on the menu bar. Menus have at most 5 levels. Set by the Menu Editor.

Order

LongDefault: 0Not in InspectorDesigner only

Position among the items with the same Parent, lowest first; equal values keep their order in the layout. Set by the Menu Editor.

Range: 0 to 32767.

Index

LongDefault: -1Read only in BASICDesigner Index row

Position of this item in its menu control array, 0 to 32767. Several menu items share one name only when every one of them has an Index. Absent from the layout, and -1 in code, when the item is not in an array.

Designer values: 0 to 32767. Clear the dedicated Index row for a non-array control; BASIC then reads -1.

Events and parameters#

Replace control with the object’s Name when creating a handler. ByRef arguments may be changed by your handler; ByVal arguments report an input value.

Click

Occurs when the user chooses the item from the menu bar, a pop-up menu or its Shortcut. Disabled or hidden items, and the items under them, never raise it.

Signature — see the complete lesson for an implementation
Private Sub control_Click()

No parameters.

Methods#

No methods are declared in this component’s built-in metadata. Use its documented properties and events; do not infer APIs from a similarly named control in another framework.

Source baseline 20f4bfed6b · Build manifest
Sources & maintenance

Original web explanation, reviewed against these repository sources. API tables and example files follow the implementation.

  • src/McBasic.Workspace/MenuRules.cs
  • src/McBasic.Workspace/MenuShortcuts.cs
  • macos/McBasicIDE/Sources/MenuEditorWindow.swift
  • tests/McBasic.Compiler.Tests/MenuCompilerChecks.cs
  • tests/McBasic.Compiler.Tests/PopupMenuChecks.cs