Table of Contents

Class Dialog

Namespace
Terminal.Gui.Views
Assembly
Terminal.Gui.dll

A modal dialog window with buttons across the bottom. When a button is pressed, Result is set to the button's index.

public class Dialog : Runnable<int?>, IDisposable, ISupportInitializeNotification, ISupportInitialize, IRunnable<int?>, IRunnable, IDesignable
Inheritance
Dialog
Implements
Derived
Inherited Members
Extension Methods

Examples

Dialog dialog = new () { Title = "Confirm" };

dialog.AddButton (new () { Title = "Cancel" });
dialog.AddButton (new () { Title = "OK" });

Label label = new () { Text = "Are you sure?" };
dialog.Add (label);

Application.Run (dialog);

if (dialog.Result == 1) // OK button (second button, index 1)
{
    // User clicked OK
}

Remarks

By default, Dialog is centered with Auto(DimAutoStyle, Dim?, Dim?) sizing and uses the Dialog color scheme when running.

To run modally, pass the dialog to Run(IRunnable, Func<Exception, bool>?). The dialog executes until terminated by QuitKey (Esc by default) or a button press.

Buttons are added via AddButton(Button) or the Buttons property. The last button added becomes the default (IsDefault). Button alignment is controlled by ButtonAlignment and ButtonAlignmentModes.

Constructors

Dialog()

Initializes a new instance of the Dialog class with no buttons.

Properties

ButtonAlignment

Determines how buttons are aligned horizontally at the bottom of the dialog.

ButtonAlignmentModes

Controls button spacing and alignment behavior.

Buttons

Gets or sets the buttons displayed at the bottom of the dialog.

Canceled

Gets whether the dialog was canceled.

DefaultBorderStyle

The default border style for new Dialog instances. Can be configured via ConfigurationManager and theme files.

DefaultButtonAlignment

The default button alignment for new Dialog instances. Can be configured via theme files.

DefaultButtonAlignmentModes

The default button alignment modes for new Dialog instances. Can be configured via theme files.

DefaultShadow

The default shadow style for new Dialog instances. Can be configured via theme files.

Methods

AddButton(Button)

Adds a Button to the bottom of the dialog.

EndInit()

Signals the View that initialization is ending. See ISupportInitialize.

OnDrawingText()

Called when the Text of the View is to be drawn.

OnDrewText()

Called when the Text of the View has been drawn.

OnGettingAttributeForRole(in VisualRole, ref Attribute)

Called when the Attribute for a GetAttributeForRole(VisualRole) is being retrieved. Implementations can return true to stop further processing and optionally set the Attribute in the event args to a different value.

OnIsRunningChanged(bool)

Called after IsRunning has changed. Override for post-state-change logic.

OnSubViewAdded(View)

Called when a SubView has been added to this View.

OnSubViewLayout(LayoutEventArgs)

Called from Terminal.Gui.ViewBase.View.LayoutSubViews() before any subviews have been laid out.