Search Results for

    Show / Hide Table of Contents

    Class MenuBar

    Provides a menu bar that spans the top of a Toplevel View with drop-down and cascading menus.

    By default, any sub-sub-menus (sub-menus of the MenuItems added to MenuBarItems) are displayed in a cascading manner, where each sub-sub-menu pops out of the sub-menu frame (either to the right or left, depending on where the sub-menu is relative to the edge of the screen). By setting UseSubMenusSingleFrame to true, this behavior can be changed such that all sub-sub-menus are drawn within a single frame below the MenuBar.

    Inheritance
    object
    Responder
    View
    MenuBar
    Implements
    IDisposable
    ISupportInitializeNotification
    ISupportInitialize
    Inherited Members
    View.Added
    View.Removed
    View.Enter
    View.Leave
    View.MouseEnter
    View.MouseLeave
    View.MouseClick
    View.CanFocusChanged
    View.EnabledChanged
    View.VisibleChanged
    View.HotKeyChanged
    View.HotKey
    View.Shortcut
    View.ShortcutTag
    View.ShortcutAction
    View.Data
    View.Driver
    View.Subviews
    View.TabIndexes
    View.TabIndex
    View.TabStop
    View.CanFocus
    View.Id
    View.IsCurrentTop
    View.WantMousePositionReports
    View.WantContinuousButtonPressed
    View.Frame
    View.LayoutStyle
    View.Bounds
    View.X
    View.Y
    View.Width
    View.Height
    View.ForceValidatePosDim
    View.GetMinWidthHeight(out Size)
    View.SetMinWidthHeight()
    View.TextFormatter
    View.SuperView
    View.UpdateTextFormatterText()
    View.ProcessResizeView()
    View.SetNeedsDisplay()
    View.ClearLayoutNeeded()
    View.SetNeedsDisplay(Rect)
    View.SetChildNeedsDisplay()
    View.Add(View)
    View.Add(params View[])
    View.RemoveAll()
    View.Remove(View)
    View.BringSubviewToFront(View)
    View.SendSubviewToBack(View)
    View.SendSubviewBackwards(View)
    View.BringSubviewForward(View)
    View.Clear()
    View.Clear(Rect)
    View.ScreenToView(int, int)
    View.ClipToBounds()
    View.SetClip(Rect)
    View.DrawFrame(Rect, int, bool)
    View.DrawHotString(ustring, Attribute, Attribute)
    View.DrawHotString(ustring, bool, ColorScheme)
    View.Move(int, int, bool)
    View.HasFocus
    View.OnAdded(View)
    View.OnRemoved(View)
    View.Focused
    View.MostFocused
    View.ColorScheme
    View.AddRune(int, int, Rune)
    View.ClearNeedsDisplay()
    View.DrawContent
    View.OnDrawContent(Rect)
    View.DrawContentComplete
    View.OnDrawContentComplete(Rect)
    View.SetFocus()
    View.KeyPress
    View.InvokeKeybindings(KeyEvent)
    View.AddKeyBinding(Key, params Command[])
    View.ReplaceKeyBinding(Key, Key)
    View.ContainsKeyBinding(Key)
    View.ClearKeybindings()
    View.ClearKeybinding(Key)
    View.ClearKeybinding(params Command[])
    View.AddCommand(Command, Func<bool?>)
    View.GetSupportedCommands()
    View.GetKeyFromCommand(params Command[])
    View.KeyDown
    View.KeyUp
    View.EnsureFocus()
    View.FocusFirst()
    View.FocusLast()
    View.FocusPrev()
    View.FocusNext()
    View.LayoutStarted
    View.LayoutComplete
    View.Initialized
    View.LayoutSubviews()
    View.Text
    View.AutoSize
    View.PreserveTrailingSpaces
    View.TextAlignment
    View.VerticalTextAlignment
    View.TextDirection
    View.IsInitialized
    View.IsAdded
    View.Enabled
    View.ClearOnVisibleFalse
    View.Border
    View.IgnoreBorderPropertyOnRedraw
    View.ToString()
    View.GetAutoSize()
    View.GetHotKeySpecifierLength(bool)
    View.GetTextFormatterBoundsSize()
    View.GetBoundsTextFormatterSize()
    View.OnMouseEnter(MouseEvent)
    View.OnMouseLeave(MouseEvent)
    View.OnMouseEvent(MouseEvent)
    View.OnMouseClick(View.MouseEventArgs)
    View.OnCanFocusChanged()
    View.OnEnabledChanged()
    View.OnVisibleChanged()
    View.Dispose(bool)
    View.BeginInit()
    View.EndInit()
    View.SetWidth(int, out int)
    View.SetHeight(int, out int)
    View.GetCurrentWidth(out int)
    View.GetCurrentHeight(out int)
    View.GetNormalColor()
    View.GetFocusColor()
    View.GetHotNormalColor()
    View.GetTopSuperView()
    Responder.Dispose()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Terminal.Gui
    Assembly: Terminal.Gui.dll
    Syntax
    public class MenuBar : View, IDisposable, ISupportInitializeNotification, ISupportInitialize
    Remarks

    The MenuBar appears on the first row of the parent Toplevel View and uses the full width.

    The MenuBar provides global hotkeys for the application. See HotKey.

    See also: ContextMenu

    Constructors

    | Edit this page View Source

    MenuBar()

    Initializes a new instance of the MenuBar.
    Declaration
    public MenuBar()
    | Edit this page View Source

    MenuBar(MenuBarItem[])

    Initializes a new instance of the MenuBar class with the specified set of toplevel menu items.
    Declaration
    public MenuBar(MenuBarItem[] menus)
    Parameters
    Type Name Description
    MenuBarItem[] menus Individual menu items; a null item will result in a separator being drawn.

    Properties

    | Edit this page View Source

    HotKeySpecifier

    The specifier character for the hotkey to all menus.
    Declaration
    public static Rune HotKeySpecifier { get; }
    Property Value
    Type Description
    Rune
    | Edit this page View Source

    IsMenuOpen

    true if the menu is open; otherwise true.
    Declaration
    public bool IsMenuOpen { get; protected set; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Key

    The Key used to activate the menu bar by keyboard.
    Declaration
    public Key Key { get; set; }
    Property Value
    Type Description
    Key
    | Edit this page View Source

    LastFocused

    Gets the view that was last focused before opening the menu.
    Declaration
    public View LastFocused { get; }
    Property Value
    Type Description
    View
    | Edit this page View Source

    Menus

    Gets or sets the array of MenuBarItems for the menu. Only set this after the MenuBar is visible.
    Declaration
    public MenuBarItem[] Menus { get; set; }
    Property Value
    Type Description
    MenuBarItem[] The menu array.
    | Edit this page View Source

    ShortcutDelimiter

    Sets or gets the shortcut delimiter separator. The default is "+".
    Declaration
    public static ustring ShortcutDelimiter { get; set; }
    Property Value
    Type Description
    ustring
    | Edit this page View Source

    UseKeysUpDownAsKeysLeftRight

    Used for change the navigation key style.
    Declaration
    public bool UseKeysUpDownAsKeysLeftRight { get; set; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    UseSubMenusSingleFrame

    Gets or sets if the sub-menus must be displayed in a single or multiple frames.

    By default any sub-sub-menus (sub-menus of the main MenuItems) are displayed in a cascading manner, where each sub-sub-menu pops out of the sub-menu frame (either to the right or left, depending on where the sub-menu is relative to the edge of the screen). By setting UseSubMenusSingleFrame to true, this behavior can be changed such that all sub-sub-menus are drawn within a single frame below the MenuBar.

    Declaration
    public bool UseSubMenusSingleFrame { get; set; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Visible

    Gets or sets a value indicating whether this Responder and all its child controls are displayed.
    Declaration
    public override bool Visible { get; set; }
    Property Value
    Type Description
    bool
    Overrides
    View.Visible

    Methods

    | Edit this page View Source

    CloseMenu(bool)

    Closes the Menu programmatically if open and not canceled (as though F9 were pressed).
    Declaration
    public bool CloseMenu(bool ignoreUseSubMenusSingleFrame = false)
    Parameters
    Type Name Description
    bool ignoreUseSubMenusSingleFrame
    Returns
    Type Description
    bool
    | Edit this page View Source

    MouseEvent(MouseEvent)

    Method invoked when a mouse event is generated
    Declaration
    public override bool MouseEvent(MouseEvent me)
    Parameters
    Type Name Description
    MouseEvent me
    Returns
    Type Description
    bool true, if the event was handled, false otherwise.
    Overrides
    Responder.MouseEvent(MouseEvent)
    | Edit this page View Source

    OnEnter(View)

    Method invoked when a view gets focus.
    Declaration
    public override bool OnEnter(View view)
    Parameters
    Type Name Description
    View view The view that is losing focus.
    Returns
    Type Description
    bool true, if the event was handled, false otherwise.
    Overrides
    View.OnEnter(View)
    | Edit this page View Source

    OnKeyDown(KeyEvent)

    Method invoked when a key is pressed.
    Declaration
    public override bool OnKeyDown(KeyEvent keyEvent)
    Parameters
    Type Name Description
    KeyEvent keyEvent Contains the details about the key that produced the event.
    Returns
    Type Description
    bool true if the event was handled
    Overrides
    View.OnKeyDown(KeyEvent)
    | Edit this page View Source

    OnKeyUp(KeyEvent)

    Method invoked when a key is released.
    Declaration
    public override bool OnKeyUp(KeyEvent keyEvent)
    Parameters
    Type Name Description
    KeyEvent keyEvent Contains the details about the key that produced the event.
    Returns
    Type Description
    bool true if the event was handled
    Overrides
    View.OnKeyUp(KeyEvent)
    | Edit this page View Source

    OnLeave(View)

    Method invoked when a view loses focus.
    Declaration
    public override bool OnLeave(View view)
    Parameters
    Type Name Description
    View view The view that is getting focus.
    Returns
    Type Description
    bool true, if the event was handled, false otherwise.
    Overrides
    View.OnLeave(View)
    | Edit this page View Source

    OnMenuAllClosed()

    Virtual method that will invoke the MenuAllClosed.
    Declaration
    public virtual void OnMenuAllClosed()
    | Edit this page View Source

    OnMenuClosing(MenuBarItem, bool, bool)

    Virtual method that will invoke the MenuClosing.
    Declaration
    public virtual MenuClosingEventArgs OnMenuClosing(MenuBarItem currentMenu, bool reopen, bool isSubMenu)
    Parameters
    Type Name Description
    MenuBarItem currentMenu The current menu to be closed.
    bool reopen Whether the current menu will be reopen.
    bool isSubMenu Whether is a sub-menu or not.
    Returns
    Type Description
    MenuClosingEventArgs
    | Edit this page View Source

    OnMenuOpened()

    Virtual method that will invoke the MenuOpened event if it's defined.
    Declaration
    public virtual void OnMenuOpened()
    | Edit this page View Source

    OnMenuOpening(MenuBarItem)

    Virtual method that will invoke the MenuOpening event if it's defined.
    Declaration
    public virtual MenuOpeningEventArgs OnMenuOpening(MenuBarItem currentMenu)
    Parameters
    Type Name Description
    MenuBarItem currentMenu The current menu to be replaced.
    Returns
    Type Description
    MenuOpeningEventArgs Returns the MenuOpeningEventArgs
    | Edit this page View Source

    OpenMenu()

    Opens the Menu programatically, as though the F9 key were pressed.
    Declaration
    public void OpenMenu()
    | Edit this page View Source

    PositionCursor()

    Positions the cursor in the right position based on the currently focused view in the chain.
    Declaration
    public override void PositionCursor()
    Overrides
    View.PositionCursor()
    | Edit this page View Source

    ProcessColdKey(KeyEvent)

    This method can be overwritten by views that want to provide accelerator functionality (Alt-key for example), but without interefering with normal ProcessKey behavior.
    Declaration
    public override bool ProcessColdKey(KeyEvent kb)
    Parameters
    Type Name Description
    KeyEvent kb
    Returns
    Type Description
    bool
    Overrides
    View.ProcessColdKey(KeyEvent)
    Remarks

    After keys are sent to the subviews on the current view, all the view are processed and the key is passed to the views to allow some of them to process the keystroke as a cold-key.

    This functionality is used, for example, by default buttons to act on the enter key. Processing this as a hot-key would prevent non-default buttons from consuming the enter keypress when they have the focus.

    | Edit this page View Source

    ProcessHotKey(KeyEvent)

    This method can be overwritten by view that want to provide accelerator functionality (Alt-key for example).
    Declaration
    public override bool ProcessHotKey(KeyEvent kb)
    Parameters
    Type Name Description
    KeyEvent kb
    Returns
    Type Description
    bool
    Overrides
    View.ProcessHotKey(KeyEvent)
    Remarks

    Before keys are sent to the subview on the current view, all the views are processed and the key is passed to the widgets to allow some of them to process the keystroke as a hot-key.

    For example, if you implement a button that has a hotkey ok "o", you would catch the combination Alt-o here. If the event is caught, you must return true to stop the keystroke from being dispatched to other views.

    | Edit this page View Source

    ProcessKey(KeyEvent)

    If the view is focused, gives the view a chance to process the keystroke.
    Declaration
    public override bool ProcessKey(KeyEvent kb)
    Parameters
    Type Name Description
    KeyEvent kb
    Returns
    Type Description
    bool
    Overrides
    View.ProcessKey(KeyEvent)
    Remarks

    Views can override this method if they are interested in processing the given keystroke. If they consume the keystroke, they must return true to stop the keystroke from being processed by other widgets or consumed by the widget engine. If they return false, the keystroke will be passed using the ProcessColdKey method to other views to process.

    The View implementation does nothing but return false, so it is not necessary to call base.ProcessKey if you derive directly from View, but you should if you derive other View subclasses.

    | Edit this page View Source

    Redraw(Rect)

    Redraws this view and its subviews; only redraws the views that have been flagged for a re-display.
    Declaration
    public override void Redraw(Rect bounds)
    Parameters
    Type Name Description
    Rect bounds The bounds (view-relative region) to redraw.
    Overrides
    View.Redraw(Rect)
    Remarks

    Always use Bounds (view-relative) when calling Redraw(Rect), NOT Frame (superview-relative).

    Views should set the color that they want to use on entry, as otherwise this will inherit the last color that was set globally on the driver.

    Overrides of Redraw(Rect) must ensure they do not set Driver.Clip to a clip region larger than the parameter, as this will cause the driver to clip the entire region.

    Events

    | Edit this page View Source

    MenuAllClosed

    Raised when all the menu is closed.
    Declaration
    public event Action MenuAllClosed
    Event Type
    Type Description
    Action
    | Edit this page View Source

    MenuClosing

    Raised when a menu is closing passing MenuClosingEventArgs.
    Declaration
    public event Action<MenuClosingEventArgs> MenuClosing
    Event Type
    Type Description
    Action<MenuClosingEventArgs>
    | Edit this page View Source

    MenuOpened

    Raised when a menu is opened.
    Declaration
    public event Action<MenuItem> MenuOpened
    Event Type
    Type Description
    Action<MenuItem>
    | Edit this page View Source

    MenuOpening

    Raised as a menu is opening.
    Declaration
    public event Action<MenuOpeningEventArgs> MenuOpening
    Event Type
    Type Description
    Action<MenuOpeningEventArgs>

    Implements

    IDisposable
    ISupportInitializeNotification
    ISupportInitialize
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX