comparison ServerMonitor/Forms/InputDialog.cs @ 9:7127d5b5ac75

Code cleanup and comments
author Brad Greco <brad@bgreco.net>
date Mon, 08 Apr 2019 21:29:54 -0400
parents c1dffaac66fa
children
comparison
equal deleted inserted replaced
8:052aa62cb42a 9:7127d5b5ac75
1 using System; 1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing; 2 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms; 3 using System.Windows.Forms;
10 4
11 namespace ServerMonitorApp 5 namespace ServerMonitorApp
12 { 6 {
7 /// <summary>Message dialog with an input box.</summary>
13 public partial class InputDialog : Form 8 public partial class InputDialog : Form
14 { 9 {
10 /// <summary>Message to show.</summary>
15 public string Message { get; set; } 11 public string Message { get; set; }
16 12
13 /// <summary>Icon to show.</summary>
17 public Icon MessageIcon { get; set; } 14 public Icon MessageIcon { get; set; }
18 15
16 /// <summary>The text entered by the user.</summary>
19 public string Input { get; private set; } = ""; 17 public string Input { get; private set; } = "";
20 18
21 public InputDialog() 19 public InputDialog()
22 { 20 {
23 InitializeComponent(); 21 InitializeComponent();
27 { 25 {
28 MessageIconPictureBox.Image = (MessageIcon ?? SystemIcons.Question).ToBitmap(); 26 MessageIconPictureBox.Image = (MessageIcon ?? SystemIcons.Question).ToBitmap();
29 MessageLabel.Text = Message; 27 MessageLabel.Text = Message;
30 } 28 }
31 29
30 /// <summary>Updates the public property with the checked state so it can be read by the dialog owner.</summary>
31 private void InputTextBox_TextChanged(object sender, EventArgs e)
32 {
33 Input = InputTextBox.Text;
34 }
35
36 /// <summary>Creates and shows an input box dialog.</summary>
37 /// <param name="message">The message to display.</param>
38 /// <param name="icon">The icon to display.</param>
39 /// <param name="owner">The dialog owner.</param>
40 /// <returns>The string entered by the user, or null if the dialog was cancelled.</returns>
32 public static string ShowDialog(string message, Icon icon = null, IWin32Window owner = null) 41 public static string ShowDialog(string message, Icon icon = null, IWin32Window owner = null)
33 { 42 {
34 using (InputDialog dialog = new InputDialog() { Message = message, MessageIcon = icon }) 43 using (InputDialog dialog = new InputDialog() { Message = message, MessageIcon = icon })
35 { 44 {
36 return dialog.ShowDialog(owner) == DialogResult.OK ? dialog.Input : null; 45 return dialog.ShowDialog(owner) == DialogResult.OK ? dialog.Input : null;
37 } 46 }
38 } 47 }
39
40 private void InputTextBox_TextChanged(object sender, EventArgs e)
41 {
42 Input = InputTextBox.Text;
43 }
44 } 48 }
45 } 49 }