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#
| Field | Meaning | Runtime access |
|---|---|---|
| Name | BASIC identifier; Index distinguishes array members | Read only |
| Caption | Visible label; & marks an access key and && means a literal ampersand | Read / write |
| Parent | ID of another menu item; empty means a menu title | Layout only |
| Order | Position among siblings | Layout only |
| Shortcut | Choose a supported unique shortcut; Ctrl maps to Command on Mac | Read only |
| Checked, Enabled, Visible | Checkmark, interaction and visibility | Read / write |
| WindowList | One top-level title can host the MDI window list | Read only |
| Index | Optional indexed menu group, 0–32767 | Read 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.
Private Sub mnuDetails_Click()
mnuDetails.Checked = Not mnuDetails.Checked
lblStatus.Visible = mnuDetails.Checked
End Sub
Private Sub cmdPopup_Click()
PopupMenu mnuActions
End SubShow an existing menu at the pointer or a chosen position#
PopupMenu menu [, flags [, x, y [, defaultItem]]]Use a menu title or submenu with children. Omitting coordinates uses the pointer; explicit coordinates are Form-client coordinates in points. Supported flags include vbPopupMenuLeftAlign, vbPopupMenuCenterAlign, vbPopupMenuRightAlign, vbPopupMenuLeftButton and vbPopupMenuRightButton. The chosen leaf still invokes its Click handler. A default item must belong to that menu.
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.
20f4bfed6b · Build manifestSources & maintenance
Original web explanation, reviewed against these repository sources. API tables and example files follow the implementation.
src/McBasic.Workspace/MenuRules.cssrc/McBasic.Workspace/MenuShortcuts.csmacos/McBasicIDE/Sources/MenuEditorWindow.swifttests/McBasic.Compiler.Tests/MenuCompilerChecks.cstests/McBasic.Compiler.Tests/PopupMenuChecks.cs