annotate ServerMonitor/Forms/InputDialog.cs @ 12:d92176c5398a

Better display of schedule name.
author Brad Greco <brad@bgreco.net>
date Mon, 15 Apr 2019 19:24:55 -0400
parents 7127d5b5ac75
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
1 using System;
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
2 using System.Drawing;
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.Windows.Forms;
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 namespace ServerMonitorApp
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 {
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
7 /// <summary>Message dialog with an input box.</summary>
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 public partial class InputDialog : Form
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 {
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
10 /// <summary>Message to show.</summary>
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 public string Message { get; set; }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
13 /// <summary>Icon to show.</summary>
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 public Icon MessageIcon { get; set; }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
16 /// <summary>The text entered by the user.</summary>
6
c1dffaac66fa - Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents: 5
diff changeset
17 public string Input { get; private set; } = "";
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19 public InputDialog()
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 {
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 InitializeComponent();
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 private void InputDialog_Load(object sender, EventArgs e)
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25 {
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
26 MessageIconPictureBox.Image = (MessageIcon ?? SystemIcons.Question).ToBitmap();
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
27 MessageLabel.Text = Message;
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
28 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
29
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
30 /// <summary>Updates the public property with the checked state so it can be read by the dialog owner.</summary>
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
31 private void InputTextBox_TextChanged(object sender, EventArgs e)
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
32 {
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
33 Input = InputTextBox.Text;
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
34 }
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
35
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
36 /// <summary>Creates and shows an input box dialog.</summary>
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
37 /// <param name="message">The message to display.</param>
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
38 /// <param name="icon">The icon to display.</param>
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
39 /// <param name="owner">The dialog owner.</param>
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
40 /// <returns>The string entered by the user, or null if the dialog was cancelled.</returns>
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41 public static string ShowDialog(string message, Icon icon = null, IWin32Window owner = null)
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
42 {
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 using (InputDialog dialog = new InputDialog() { Message = message, MessageIcon = icon })
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
44 {
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
45 return dialog.ShowDialog(owner) == DialogResult.OK ? dialog.Input : null;
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
diff changeset
49 }