using System;
using System.Drawing;
using System.Windows.Forms;
namespace ServerMonitorApp
{
/// Message dialog with an input box.
public partial class InputDialog : Form
{
/// Message to show.
public string Message { get; set; }
/// Icon to show.
public Icon MessageIcon { get; set; }
/// The text entered by the user.
public string Input { get; private set; } = "";
public InputDialog()
{
InitializeComponent();
}
private void InputDialog_Load(object sender, EventArgs e)
{
MessageIconPictureBox.Image = (MessageIcon ?? SystemIcons.Question).ToBitmap();
MessageLabel.Text = Message;
}
/// Updates the public property with the checked state so it can be read by the dialog owner.
private void InputTextBox_TextChanged(object sender, EventArgs e)
{
Input = InputTextBox.Text;
}
/// Creates and shows an input box dialog.
/// The message to display.
/// The icon to display.
/// The dialog owner.
/// The string entered by the user, or null if the dialog was cancelled.
public static string ShowDialog(string message, Icon icon = null, IWin32Window owner = null)
{
using (InputDialog dialog = new InputDialog() { Message = message, MessageIcon = icon })
{
return dialog.ShowDialog(owner) == DialogResult.OK ? dialog.Input : null;
}
}
}
}