mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
namespace Terminal {
|
|
|
|
/// <summary>
|
|
/// Message box displays a modal message to the user, with a title, a message and a series of options that the user can choose from.
|
|
/// </summary>
|
|
public class MessageBox {
|
|
/// <summary>
|
|
/// Runs the dialog bo
|
|
/// </summary>
|
|
/// <returns>The index of the selected button, or -1 if the user pressed ESC to close the dialog.</returns>
|
|
/// <param name="width">Width for the window.</param>
|
|
/// <param name="height">Height for the window.</param>
|
|
/// <param name="title">Title for the query.</param>
|
|
/// <param name="message">Message to display, might contain multiple lines..</param>
|
|
/// <param name="buttons">Array of buttons to add.</param>
|
|
public static int Query (int width, int height, string title, string message, params string [] buttons)
|
|
{
|
|
int lines = Label.MeasureLines (message, width);
|
|
int clicked = -1, count = 0;
|
|
|
|
var d = new Dialog (title, width, height);
|
|
foreach (var s in buttons) {
|
|
int n = count++;
|
|
var b = new Button (s);
|
|
b.Clicked += delegate {
|
|
clicked = n;
|
|
d.Running = false;
|
|
};
|
|
d.AddButton (b);
|
|
}
|
|
if (message != null) {
|
|
var l = new Label ((width - 4 - message.Length) / 2, 0, message);
|
|
d.Add (l);
|
|
}
|
|
|
|
Application.Run (d);
|
|
return clicked;
|
|
}
|
|
}
|
|
}
|