view ServerMonitor/Forms/InputDialog.cs @ 18:b713b9db4c82

HTTP checks.
author Brad Greco <brad@bgreco.net>
date Mon, 27 May 2019 15:40:44 -0400
parents 7127d5b5ac75
children
line wrap: on
line source

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ServerMonitorApp
{
    /// <summary>Message dialog with an input box.</summary>
    public partial class InputDialog : Form
    {
        /// <summary>Message to show.</summary>
        public string Message { get; set; }

        /// <summary>Icon to show.</summary>
        public Icon MessageIcon { get; set; }

        /// <summary>The text entered by the user.</summary>
        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;
        }

        /// <summary>Updates the public property with the checked state so it can be read by the dialog owner.</summary>
        private void InputTextBox_TextChanged(object sender, EventArgs e)
        {
            Input = InputTextBox.Text;
        }

        /// <summary>Creates and shows an input box dialog.</summary>
        /// <param name="message">The message to display.</param>
        /// <param name="icon">The icon to display.</param>
        /// <param name="owner">The dialog owner.</param>
        /// <returns>The string entered by the user, or null if the dialog was cancelled.</returns>
        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;
            }
        }
    }
}