McBasic™Get McBasic™ ↗
Build 881
Practical guide

Build menus with the Menu Editor

Design a menu tree, wire real Click handlers and reuse an action menu as a popup.

Edit the menu as one tree#

Open the intended Form and choose Design → Menu Editor… (Command–E). Give each item a BASIC Name and a visible Caption. Insert adds an item; indent/outdent establishes the hierarchy and Move Up/Down orders siblings. Confirm the editor to apply the tree as one edit; cancelling leaves the Form unchanged. The menu preview is not a row of buttons that you draw on the Form.

New menus use MenuItem components. The old Menu component remains readable for existing projects, but cannot coexist with MenuItem on the same Form. Use the editor’s conversion workflow on a practice copy and review the converted handlers before accepting it.

Know which fields belong to design time#

FieldMeaningRuntime access
NameBASIC identifier; Index distinguishes array membersRead only
CaptionVisible label; & marks an access key and && means a literal ampersandRead / write
ParentID of another menu item; empty means a menu titleLayout only
OrderPosition among siblingsLayout only
ShortcutChoose a supported unique shortcut; Ctrl maps to Command on MacRead only
Checked, Enabled, VisibleCheckmark, interaction and visibilityRead / write
WindowListOne top-level title can host the MDI window listRead only
IndexOptional indexed menu group, 0–32767Read only

A separator has Caption -, sits below a title and cannot have children. Maximum depth is five, counting the title. Array siblings share a Parent. Menu items belong to a Form, not a UserControl. Check reports invalid trees as MCB2103 and conflicting shortcuts as MCB2104.

Keep command state and behavior together#

A normal menu command has a parameterless Click handler. A menu array adds Index first. Caption changes do not rename the handler. The full Modern Workbench supplies the layout, menu tree, every handler and a popup button.

Requires the complete ModernWorkbench layout
Private Sub mnuDetails_Click()
    mnuDetails.Checked = Not mnuDetails.Checked
    lblStatus.Visible = mnuDetails.Checked
End Sub

Private Sub cmdPopup_Click()
    PopupMenu mnuActions
End Sub

Test where the command will actually appear#

On Mac the menu belongs to the active application; on Windows and Linux it is inside the window. Ctrl shortcuts become Command shortcuts on Mac. MCB2405 warns when macOS reserves a shortcut. The runtime owns its About box: an item named mnuAbout is an ordinary item, not an override. A non-array mnuSettings moves to the application menu on Mac and cannot contain children. Test keyboard access as well as clicks.

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