Search Results for

    Show / Hide Table of Contents

    Class Toplevel

    Toplevel views can be modally executed. They are used for both an application's main view (filling the entire screeN and for pop-up views such as Dialog, MessageBox, and Wizard.
    Inheritance
    System.Object
    Responder
    View
    Toplevel
    Border.ToplevelContainer
    Window
    Implements
    System.IDisposable
    System.ComponentModel.ISupportInitializeNotification
    System.ComponentModel.ISupportInitialize
    Remarks

    Toplevels can be modally executing views, started by calling Run(Toplevel, Func<Exception, Boolean>). They return control to the caller when RequestStop(Toplevel) has been called (which sets the Running property to false).

    A Toplevel is created when an application initializes Terminal.Gui by calling Init(ConsoleDriver, IMainLoopDriver). The application Toplevel can be accessed via Top. Additional Toplevels can be created and run (e.g. Dialogs. To run a Toplevel, create the Toplevel and call Run(Toplevel, Func<Exception, Boolean>).

    Toplevels can also opt-in to more sophisticated initialization by implementing System.ComponentModel.ISupportInitialize. When they do so, the System.ComponentModel.ISupportInitialize.BeginInit and System.ComponentModel.ISupportInitialize.EndInit methods will be called before running the view. If first-run-only initialization is preferred, the System.ComponentModel.ISupportInitializeNotification can be implemented too, in which case the System.ComponentModel.ISupportInitialize methods will only be called if System.ComponentModel.ISupportInitializeNotification.IsInitialized is false. This allows proper View inheritance hierarchies to override base class layout code optimally by doing so only on first run, instead of on every run.

    Inherited Members
    View.GetMinWidthHeight(Size)
    View.SetMinWidthHeight()
    View.UpdateTextFormatterText()
    View.ProcessResizeView()
    View.SetNeedsDisplay()
    View.ClearLayoutNeeded()
    View.SetNeedsDisplay(Rect)
    View.SetChildNeedsDisplay()
    View.Add(View[])
    View.BringSubviewToFront(View)
    View.SendSubviewToBack(View)
    View.SendSubviewBackwards(View)
    View.BringSubviewForward(View)
    View.Clear()
    View.Clear(Rect)
    View.ScreenToView(Int32, Int32)
    View.ClipToBounds()
    View.SetClip(Rect)
    View.DrawFrame(Rect, Int32, Boolean)
    View.DrawHotString(ustring, Attribute, Attribute)
    View.DrawHotString(ustring, Boolean, ColorScheme)
    View.Move(Int32, Int32, Boolean)
    View.OnAdded(View)
    View.OnRemoved(View)
    View.OnEnter(View)
    View.OnLeave(View)
    View.AddRune(Int32, Int32, Rune)
    View.ClearNeedsDisplay()
    View.OnDrawContent(Rect)
    View.OnDrawContentComplete(Rect)
    View.SetFocus()
    View.InvokeKeybindings(KeyEvent)
    View.AddKeyBinding(Key, Command)
    View.ReplaceKeyBinding(Key, Key)
    View.ContainsKeyBinding(Key)
    View.ClearKeybindings()
    View.ClearKeybinding(Key)
    View.ClearKeybinding(Command)
    View.AddCommand(Command, Func<Nullable<Boolean>>)
    View.GetSupportedCommands()
    View.GetKeyFromCommand(Command)
    View.ProcessHotKey(KeyEvent)
    View.EnsureFocus()
    View.FocusFirst()
    View.FocusLast()
    View.FocusPrev()
    View.FocusNext()
    View.LayoutSubviews()
    View.ToString()
    View.GetAutoSize()
    View.GetHotKeySpecifierLength(Boolean)
    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(Boolean)
    View.BeginInit()
    View.EndInit()
    View.SetWidth(Int32, Int32)
    View.SetHeight(Int32, Int32)
    View.GetCurrentWidth(Int32)
    View.GetCurrentHeight(Int32)
    View.GetNormalColor()
    View.GetTopSuperView()
    View.HotKey
    View.HotKeySpecifier
    View.Shortcut
    View.ShortcutTag
    View.ShortcutAction
    View.Data
    View.Driver
    View.Subviews
    View.TabIndexes
    View.TabIndex
    View.TabStop
    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.TextFormatter
    View.SuperView
    View.HasFocus
    View.Focused
    View.MostFocused
    View.ColorScheme
    View.Text
    View.AutoSize
    View.PreserveTrailingSpaces
    View.TextAlignment
    View.VerticalTextAlignment
    View.TextDirection
    View.IsInitialized
    View.IsAdded
    View.Enabled
    View.Visible
    View.Border
    View.Added
    View.Removed
    View.Enter
    View.Leave
    View.MouseEnter
    View.MouseLeave
    View.MouseClick
    View.CanFocusChanged
    View.EnabledChanged
    View.VisibleChanged
    View.HotKeyChanged
    View.DrawContent
    View.DrawContentComplete
    View.KeyPress
    View.KeyDown
    View.KeyUp
    View.LayoutStarted
    View.LayoutComplete
    View.Initialized
    Responder.Dispose()
    Namespace: Terminal.Gui
    Assembly: Terminal.Gui.dll
    Syntax
    public class Toplevel : View

    Constructors

    Toplevel()

    Initializes a new instance of the Toplevel class with Computed layout, defaulting to full screen.
    Declaration
    public Toplevel()

    Toplevel(Rect)

    Initializes a new instance of the Toplevel class with the specified Absolute layout.
    Declaration
    public Toplevel(Rect frame)
    Parameters
    Type Name Description
    Rect frame A superview-relative rectangle specifying the location and size for the new Toplevel

    Properties

    CanFocus

    Gets or sets a value indicating whether this Toplevel can focus.
    Declaration
    public override bool CanFocus { get; }
    Property Value
    Type Description
    System.Boolean true if can focus; otherwise, false.
    Overrides
    View.CanFocus

    IsMdiChild

    Gets or sets if this Toplevel is a Mdi child.
    Declaration
    public bool IsMdiChild { get; }
    Property Value
    Type Description
    System.Boolean

    IsMdiContainer

    Gets or sets if this Toplevel is a Mdi container.
    Declaration
    public bool IsMdiContainer { get; set; }
    Property Value
    Type Description
    System.Boolean

    MenuBar

    Gets or sets the menu for this Toplevel.
    Declaration
    public virtual MenuBar MenuBar { get; set; }
    Property Value
    Type Description
    MenuBar

    Modal

    Determines whether the Toplevel is modal or not. If set to false (the default):
    • ProcessKey(KeyEvent) events will propagate keys upwards.
    • The Toplevel will act as an embedded view (not a modal/pop-up).
    If set to true:
    • ProcessKey(KeyEvent) events will NOT propogate keys upwards.
    • The Toplevel will and look like a modal (pop-up) (e.g. see Dialog.
    Declaration
    public bool Modal { get; set; }
    Property Value
    Type Description
    System.Boolean

    Running

    Gets or sets whether the MainLoop for this Toplevel is running or not.
    Declaration
    public bool Running { get; set; }
    Property Value
    Type Description
    System.Boolean

    StatusBar

    Gets or sets the status bar for this Toplevel.
    Declaration
    public virtual StatusBar StatusBar { get; set; }
    Property Value
    Type Description
    StatusBar

    Methods

    Add(View)

    Adds a subview (child) to this view.
    Declaration
    public override void Add(View view)
    Parameters
    Type Name Description
    View view
    Overrides
    View.Add(View)

    Create()

    Convenience factory method that creates a new Toplevel with the current terminal dimensions.
    Declaration
    public static Toplevel Create()
    Returns
    Type Description
    Toplevel The created Toplevel.

    GetTopMdiChild(Type, String[])

    Gets the current visible Toplevel Mdi child that matches the arguments pattern.
    Declaration
    public View GetTopMdiChild(Type type = null, string[] exclude = null)
    Parameters
    Type Name Description
    System.Type type The type.
    System.String[] exclude The strings to exclude.
    Returns
    Type Description
    View The matched view.

    MouseEvent(MouseEvent)

    Method invoked when a mouse event is generated
    Declaration
    public override bool MouseEvent(MouseEvent mouseEvent)
    Parameters
    Type Name Description
    MouseEvent mouseEvent Contains the details about the mouse event.
    Returns
    Type Description
    System.Boolean true, if the event was handled, false otherwise.
    Overrides
    Responder.MouseEvent(MouseEvent)

    MoveNext()

    Move to the next Mdi child from the MdiTop.
    Declaration
    public virtual void MoveNext()

    MovePrevious()

    Move to the previous Mdi child from the MdiTop.
    Declaration
    public virtual void MovePrevious()

    OnAlternateBackwardKeyChanged(Key)

    Virtual method to invoke the AlternateBackwardKeyChanged event.
    Declaration
    public virtual void OnAlternateBackwardKeyChanged(Key oldKey)
    Parameters
    Type Name Description
    Key oldKey

    OnAlternateForwardKeyChanged(Key)

    Virtual method to invoke the AlternateForwardKeyChanged event.
    Declaration
    public virtual void OnAlternateForwardKeyChanged(Key oldKey)
    Parameters
    Type Name Description
    Key oldKey

    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
    System.Boolean true if the event was handled
    Overrides
    View.OnKeyDown(KeyEvent)

    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
    System.Boolean true if the event was handled
    Overrides
    View.OnKeyUp(KeyEvent)

    OnLoaded()

    Called from Begin(Toplevel) before the Toplevel redraws for the first time.
    Declaration
    public virtual void OnLoaded()

    OnQuitKeyChanged(Key)

    Virtual method to invoke the QuitKeyChanged event.
    Declaration
    public virtual void OnQuitKeyChanged(Key oldKey)
    Parameters
    Type Name Description
    Key oldKey

    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()

    PositionToplevel(Toplevel)

    Virtual method enabling implementation of specific positions for inherited Toplevel views.
    Declaration
    public virtual void PositionToplevel(Toplevel top)
    Parameters
    Type Name Description
    Toplevel top The toplevel.

    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 keyEvent)
    Parameters
    Type Name Description
    KeyEvent keyEvent Contains the details about the key that produced the event.
    Returns
    Type Description
    System.Boolean
    Overrides
    View.ProcessColdKey(KeyEvent)

    ProcessKey(KeyEvent)

    If the view is focused, gives the view a chance to process the keystroke.
    Declaration
    public override bool ProcessKey(KeyEvent keyEvent)
    Parameters
    Type Name Description
    KeyEvent keyEvent Contains the details about the key that produced the event.
    Returns
    Type Description
    System.Boolean
    Overrides
    View.ProcessKey(KeyEvent)

    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)

    Remove(View)

    Removes a subview added via Add(View) or Add(View[]) from this View.
    Declaration
    public override void Remove(View view)
    Parameters
    Type Name Description
    View view
    Overrides
    View.Remove(View)

    RemoveAll()

    Removes all subviews (children) added via Add(View) or Add(View[]) from this View.
    Declaration
    public override void RemoveAll()
    Overrides
    View.RemoveAll()

    RequestStop()

    Stops and closes this Toplevel. If this Toplevel is the top-most Toplevel, RequestStop(Toplevel) will be called, causing the application to exit.
    Declaration
    public virtual void RequestStop()

    RequestStop(Toplevel)

    Stops and closes the Toplevel specified by top. If top is the top-most Toplevel, RequestStop(Toplevel) will be called, causing the application to exit.
    Declaration
    public virtual void RequestStop(Toplevel top)
    Parameters
    Type Name Description
    Toplevel top The toplevel to request stop.

    ShowChild(Toplevel)

    Shows the Mdi child indicated by top, setting it as Current.
    Declaration
    public virtual bool ShowChild(Toplevel top = null)
    Parameters
    Type Name Description
    Toplevel top The Toplevel.
    Returns
    Type Description
    System.Boolean true if the toplevel can be shown or false if not.

    WillPresent()

    Invoked by Begin(Toplevel) as part of Run(Toplevel, Func<Exception, Boolean>) after the views have been laid out, and before the views are drawn for the first time.
    Declaration
    public virtual void WillPresent()

    Events

    Activate

    Invoked when the Toplevel Application.RunState becomes the Current Toplevel.
    Declaration
    public event Action<Toplevel> Activate
    Event Type
    Type Description
    System.Action<Toplevel>

    AllChildClosed

    Invoked when the last child of the Toplevel Application.RunState is closed from by Terminal.Gui.Application.End(Terminal.Gui.View).
    Declaration
    public event Action AllChildClosed
    Event Type
    Type Description
    System.Action

    AlternateBackwardKeyChanged

    Invoked when the AlternateBackwardKey is changed.
    Declaration
    public event Action<Key> AlternateBackwardKeyChanged
    Event Type
    Type Description
    System.Action<Key>

    AlternateForwardKeyChanged

    Invoked when the AlternateForwardKey is changed.
    Declaration
    public event Action<Key> AlternateForwardKeyChanged
    Event Type
    Type Description
    System.Action<Key>

    ChildClosed

    Invoked when a child of the Toplevel Application.RunState is closed by Terminal.Gui.Application.End(Terminal.Gui.View).
    Declaration
    public event Action<Toplevel> ChildClosed
    Event Type
    Type Description
    System.Action<Toplevel>

    ChildLoaded

    Invoked when a child Toplevel's Application.RunState has been loaded.
    Declaration
    public event Action<Toplevel> ChildLoaded
    Event Type
    Type Description
    System.Action<Toplevel>

    ChildUnloaded

    Invoked when a cjhild Toplevel's Application.RunState has been unloaded.
    Declaration
    public event Action<Toplevel> ChildUnloaded
    Event Type
    Type Description
    System.Action<Toplevel>

    Closed

    Invoked when the Toplevel's Application.RunState is closed by Terminal.Gui.Application.End(Terminal.Gui.View).
    Declaration
    public event Action<Toplevel> Closed
    Event Type
    Type Description
    System.Action<Toplevel>

    Closing

    Invoked when the Toplevel's Application.RunState is being closed by RequestStop(Toplevel).
    Declaration
    public event Action<ToplevelClosingEventArgs> Closing
    Event Type
    Type Description
    System.Action<ToplevelClosingEventArgs>

    Deactivate

    Invoked when the ToplevelApplication.RunState ceases to be the Current Toplevel.
    Declaration
    public event Action<Toplevel> Deactivate
    Event Type
    Type Description
    System.Action<Toplevel>

    Loaded

    Invoked when the Toplevel Application.RunState has begin loaded. A Loaded event handler is a good place to finalize initialization before calling RunLoop(Application.RunState, Boolean).
    Declaration
    public event Action Loaded
    Event Type
    Type Description
    System.Action

    QuitKeyChanged

    Invoked when the QuitKey is changed.
    Declaration
    public event Action<Key> QuitKeyChanged
    Event Type
    Type Description
    System.Action<Key>

    Ready

    Invoked when the Toplevel MainLoop has started it's first iteration. Subscribe to this event to perform tasks when the Toplevel has been laid out and focus has been set. changes.

    A Ready event handler is a good place to finalize initialization after calling Run(Func<Exception, Boolean>) on this Toplevel.

    Declaration
    public event Action Ready
    Event Type
    Type Description
    System.Action

    Resized

    Invoked when the terminal has been resized. The new Size of the terminal is provided.
    Declaration
    public event Action<Size> Resized
    Event Type
    Type Description
    System.Action<Size>

    Unloaded

    Invoked when the Toplevel Application.RunState has been unloaded. A Unloaded event handler is a good place to dispose objects after calling End(Application.RunState).
    Declaration
    public event Action Unloaded
    Event Type
    Type Description
    System.Action

    Implements

    System.IDisposable
    System.ComponentModel.ISupportInitializeNotification
    System.ComponentModel.ISupportInitialize
    In This Article
    Back to top Generated by DocFX