39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
namespace UI_WinForms.Dialogs;
|
|
|
|
public partial class InputDialog : Form
|
|
{
|
|
private InputDialog()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
public static InputResult Show(string message, string title, string placeholder = "", string preloadedText = "", string okButtonText = "Ok", string cancelButtonText = "Cancel")
|
|
{
|
|
using var inputDialog = new InputDialog();
|
|
inputDialog.labelHead.Text = message;
|
|
inputDialog.Text = title;
|
|
inputDialog.textBoxInput.PlaceholderText = placeholder;
|
|
inputDialog.textBoxInput.Text = preloadedText;
|
|
inputDialog.buttonOk.Text = okButtonText;
|
|
inputDialog.buttonCancel.Text = cancelButtonText;
|
|
|
|
return new InputResult(inputDialog.ShowDialog(), inputDialog.textBoxInput.Text, inputDialog.checkBoxIsRoot.Checked);
|
|
}
|
|
|
|
private void textBoxInput_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode is Keys.Enter or Keys.Return)
|
|
this.buttonOk.PerformClick();
|
|
}
|
|
|
|
private void buttonOk_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(this.textBoxInput.Text))
|
|
{
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
}
|
|
|
|
public readonly record struct InputResult(DialogResult DialogResult, string Text, bool IsRoot);
|
|
} |