Menu Demo Example
The Menu Demo shows how to create a traditional menu bar interface with dropdown menus, keyboard shortcuts, and checkable menu items.
What It Demonstrates
Section titled “What It Demonstrates”MenuBarwidget- Creating menus with subitems
- Menu separators
- Checkable menu items
- Keyboard shortcuts (hotkeys)
- Event handling for menu actions
Key Features
Section titled “Key Features”Creating Menus
Section titled “Creating Menus”var menuBar = new MenuBar{ X = 0, Y = 0, Height = 1, ForegroundColor = Color.Black, BackgroundColor = ColorHelper.FromRgb(200, 200, 200)};Adding Menu Items
Section titled “Adding Menu Items”menuBar.AddMenu("File", new MenuItem("New", () => statusBar.LeftText = "New file created", 'N'), new MenuItem("Open", () => statusBar.LeftText = "Open file dialog", 'O'), new MenuItem("Save", () => statusBar.LeftText = "File saved", 'S'), MenuItem.Separator(), new MenuItem("Exit", () => app.Stop(), 'x'));Checkable Menu Items
Section titled “Checkable Menu Items”var showToolbarItem = new MenuItem("Show Toolbar", null, 'T') { Checked = true };showToolbarItem.Selected += () =>{ showToolbarItem.Checked = !showToolbarItem.Checked; statusBar.LeftText = $"Toolbar: {(showToolbarItem.Checked ? "Visible" : "Hidden")}";};Keyboard Navigation
Section titled “Keyboard Navigation”- Tab: Focus menu bar
- Left/Right Arrow: Navigate menus
- Enter/Space/Down: Open dropdown
- Up/Down Arrow: Navigate menu items
- Enter/Space: Select item
- Escape: Close dropdown
Running the Example
Section titled “Running the Example”cd examples/Elaris.Examples.MenuDemodotnet runLearning Points
Section titled “Learning Points”- Menus provide a familiar desktop application interface
- Keyboard shortcuts make menus accessible
- Checkable items can toggle state
- Separators organize menu items visually