Table of Contents

Class MenuBuilder

Namespace
SharpConsoleUI.Builders
Assembly
SharpConsoleUI.dll

Fluent builder for creating MenuControl instances with a clean, chainable API.

public class MenuBuilder
Inheritance
MenuBuilder
Inherited Members

Methods

AddItem(string, Action)

Adds a simple menu item with text and action (no shortcut).

public MenuBuilder AddItem(string text, Action action)

Parameters

text string

The text to display for this menu item.

action Action

The action to execute when selected.

Returns

MenuBuilder

AddItem(string, Action, Color)

Adds a simple menu item with text, action, and custom foreground color.

public MenuBuilder AddItem(string text, Action action, Color foregroundColor)

Parameters

text string

The text to display for this menu item.

action Action

The action to execute when selected.

foregroundColor Color

The custom foreground color for this item.

Returns

MenuBuilder

AddItem(string, Action<MenuItemBuilder>)

Adds a menu item with subitems using a configuration action.

public MenuBuilder AddItem(string text, Action<MenuItemBuilder> configure)

Parameters

text string

The text to display for this menu item.

configure Action<MenuItemBuilder>

Action to configure the menu item's children.

Returns

MenuBuilder

AddItem(string, string, Action)

Adds a simple menu item with text, shortcut, and action.

public MenuBuilder AddItem(string text, string shortcut, Action action)

Parameters

text string

The text to display for this menu item.

shortcut string

The keyboard shortcut text (display only).

action Action

The action to execute when selected.

Returns

MenuBuilder

AddItem(string, string, Action, Color)

Adds a simple menu item with text, shortcut, action, and custom foreground color.

public MenuBuilder AddItem(string text, string shortcut, Action action, Color foregroundColor)

Parameters

text string

The text to display for this menu item.

shortcut string

The keyboard shortcut text (display only).

action Action

The action to execute when selected.

foregroundColor Color

The custom foreground color for this item.

Returns

MenuBuilder

AddSeparator()

Adds a separator line to the menu.

public MenuBuilder AddSeparator()

Returns

MenuBuilder

Build()

Builds and returns the configured MenuControl instance.

public MenuControl Build()

Returns

MenuControl

Horizontal()

Sets the menu orientation to horizontal (menu bar style).

public MenuBuilder Horizontal()

Returns

MenuBuilder

OnItemHovered(EventHandler<MenuItem>)

Registers an event handler for when a menu item is hovered.

public MenuBuilder OnItemHovered(EventHandler<MenuItem> handler)

Parameters

handler EventHandler<MenuItem>

Returns

MenuBuilder

OnItemSelected(WindowEventHandler<MenuItem>)

Registers an event handler for when a menu item is selected, with access to the parent window.

public MenuBuilder OnItemSelected(WindowEventHandler<MenuItem> handler)

Parameters

handler WindowEventHandler<MenuItem>

Returns

MenuBuilder

OnItemSelected(EventHandler<MenuItem>)

Registers an event handler for when a menu item is selected.

public MenuBuilder OnItemSelected(EventHandler<MenuItem> handler)

Parameters

handler EventHandler<MenuItem>

Returns

MenuBuilder

Sticky()

Enables sticky mode, where the menu keeps focus when dropdowns are open.

public MenuBuilder Sticky()

Returns

MenuBuilder

Vertical()

Sets the menu orientation to vertical (sidebar style).

public MenuBuilder Vertical()

Returns

MenuBuilder

WithDropdownBackgroundColor(Color)

Sets the background color for dropdown menus.

public MenuBuilder WithDropdownBackgroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithDropdownColors(Color, Color, Color, Color)

Sets all dropdown colors at once.

public MenuBuilder WithDropdownColors(Color background, Color foreground, Color highlightBackground, Color highlightForeground)

Parameters

background Color
foreground Color
highlightBackground Color
highlightForeground Color

Returns

MenuBuilder

WithDropdownForegroundColor(Color)

Sets the foreground color for dropdown menu items.

public MenuBuilder WithDropdownForegroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithDropdownHighlightBackgroundColor(Color)

Sets the background color for highlighted dropdown items.

public MenuBuilder WithDropdownHighlightBackgroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithDropdownHighlightForegroundColor(Color)

Sets the foreground color for highlighted dropdown items.

public MenuBuilder WithDropdownHighlightForegroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithMenuBarBackgroundColor(Color)

Sets the background color for the menu bar (top-level items).

public MenuBuilder WithMenuBarBackgroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithMenuBarColors(Color, Color, Color, Color)

Sets all menu bar colors at once.

public MenuBuilder WithMenuBarColors(Color background, Color foreground, Color highlightBackground, Color highlightForeground)

Parameters

background Color
foreground Color
highlightBackground Color
highlightForeground Color

Returns

MenuBuilder

WithMenuBarForegroundColor(Color)

Sets the foreground color for the menu bar (top-level items).

public MenuBuilder WithMenuBarForegroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithMenuBarHighlightBackgroundColor(Color)

Sets the background color for highlighted menu bar items.

public MenuBuilder WithMenuBarHighlightBackgroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithMenuBarHighlightForegroundColor(Color)

Sets the foreground color for highlighted menu bar items.

public MenuBuilder WithMenuBarHighlightForegroundColor(Color color)

Parameters

color Color

Returns

MenuBuilder

WithName(string)

Sets the name of the menu control for identification.

public MenuBuilder WithName(string name)

Parameters

name string

Returns

MenuBuilder

Operators

implicit operator MenuControl(MenuBuilder)

Allows implicit conversion from MenuBuilder to MenuControl.

public static implicit operator MenuControl(MenuBuilder builder)

Parameters

builder MenuBuilder

Returns

MenuControl