Mercurial > servermonitor
annotate ServerMonitor/Forms/InputDialog.cs @ 29:f6235dc0a8ec
Add ability to play a sound on check failure.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Fri, 14 Jun 2019 21:01:55 -0400 |
parents | 7127d5b5ac75 |
children |
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 | 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 | 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 | 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 | 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 | 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> | |
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 } |