Table of Contents

Class MessageBox

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

Displays a modal message box with a title, message, and buttons. Returns the index of the selected button, or null if the user cancels with QuitKey.

public static class MessageBox
Inheritance
MessageBox
Inherited Members

Remarks

MessageBox provides static methods for displaying modal dialogs with customizable buttons and messages. All methods return int? where the value is the 0-based index of the button pressed, or null if the user pressed QuitKey (typically Esc).

Query(IApplication, string, string, params string[]) uses the default Dialog color scheme. ErrorQuery(IApplication, string, string, params string[]) uses the Error color scheme.

Important: All MessageBox methods require an IApplication instance to be passed. This enables proper modal dialog management and respects the application's lifecycle. Pass your application instance (from Create(ITimeProvider?)) or use the legacy Instance if using the static Application pattern.

Example using instance-based pattern:

IApplication app = Application.Create();
    app.Init();
int? result = MessageBox.Query(app, "Quit Demo", "Are you sure you want to quit?", "_No", "_Yes");
if (result == 1) // User clicked "Yes"
    app.RequestStop();
else if (result == null) // User pressed Esc
    // Handle cancellation

app.Shutdown();</code></pre>

Example using legacy static pattern:

Application.Init();
int? result = MessageBox.Query(ApplicationImpl.Instance, "Quit Demo", "Are you sure?", "_No", "_Yes");
if (result == 1) // User clicked "Yes"
    Application.RequestStop();

Application.Shutdown();</code></pre>

Properties

DefaultBorderStyle

Defines the default border styling for MessageBox. Can be configured via ConfigurationManager.

DefaultButtonAlignment

The default Alignment for Dialog.

Methods

ErrorQuery(IApplication, string, string, int, bool, params string[])

Displays an auto-sized error MessageBox with a default button and word-wrap control.

ErrorQuery(IApplication, string, string, params string[])

Displays an auto-sized error MessageBox.

Query(IApplication, int, int, string, string, params string[])

Displays a MessageBox with fixed dimensions.

Query(IApplication, string, string, int, bool, params string[])

Displays an auto-sized MessageBox with a default button and word-wrap control.

Query(IApplication, string, string, int, params string[])

Displays an auto-sized MessageBox with a default button.

Query(IApplication, string, string, params string[])

Displays an auto-sized MessageBox.