2 using System.Drawing;
\r
3 using System.Windows.Forms;
\r
5 namespace AppliStation.Util
\r
8 /// Description of OptionDialog.
\r
10 public partial class OptionDialog : Form
\r
12 private object userInputValue = null;
\r
14 public OptionDialog()
\r
17 // The InitializeComponent() call is required for Windows Forms designer support.
\r
19 InitializeComponent();
\r
22 private void SomeButtonClick(object sender, EventArgs e)
\r
27 private void HandleUserInput(object sender, EventArgs e)
\r
29 TextBoxBase textBox = sender as TextBoxBase;
\r
30 RadioButton radioButton = sender as RadioButton;
\r
32 if (textBox != null) {
\r
33 this.userInputValue = textBox.Text;
\r
35 if (radioButton != null) {
\r
36 this.userInputValue = radioButton.Tag;
\r
40 public string MainInstructionText {
\r
42 mainInstLabel.Text = value ?? string.Empty;
\r
43 mainInstLabel.Visible = ! string.IsNullOrEmpty(value);
\r
45 get { return mainInstLabel.Text; }
\r
47 public string ContentText {
\r
49 contentLabel.Text = value ?? string.Empty;
\r
50 contentLabel.Visible = ! string.IsNullOrEmpty(value);
\r
52 get { return mainInstLabel.Text; }
\r
54 public Image Image {
\r
56 iconPictureBox.Image = value;
\r
57 if (value != null) {
\r
58 iconPictureBox.Size = new Size(32, 32);
\r
60 iconPictureBox.Size = new Size(0, 0);
\r
63 get { return iconPictureBox.Image; }
\r
65 public MessageBoxButtons Buttons {
\r
67 okButton.Enabled = okButton.Visible = (value == MessageBoxButtons.OK) || (value == MessageBoxButtons.OKCancel);
\r
68 cancelButton.Enabled = cancelButton.Visible = (value == MessageBoxButtons.OKCancel) || (value == MessageBoxButtons.YesNoCancel);
\r
69 yesButton.Enabled = yesButton.Visible = (value == MessageBoxButtons.YesNo) || (value == MessageBoxButtons.YesNoCancel);
\r
70 noButton.Enabled = noButton.Visible = (value == MessageBoxButtons.YesNo) || (value == MessageBoxButtons.YesNoCancel);
\r
72 if (okButton.Enabled) {
\r
73 this.AcceptButton = okButton;
\r
74 } else if (yesButton.Enabled) {
\r
75 this.AcceptButton = yesButton;
\r
79 bool ok = okButton.Enabled;
\r
80 bool cancel = cancelButton.Enabled;
\r
81 bool yes = yesButton.Enabled;
\r
82 bool no = noButton.Enabled;
\r
84 if (ok && !cancel && !yes && !no) {
\r
85 return MessageBoxButtons.OK;
\r
86 } else if (ok && cancel && !yes && !no) {
\r
87 return MessageBoxButtons.OKCancel;
\r
88 } else if (!ok && !cancel && yes && no) {
\r
89 return MessageBoxButtons.YesNo;
\r
90 } else if (!ok && cancel && yes && no) {
\r
91 return MessageBoxButtons.YesNoCancel;
\r
93 return (MessageBoxButtons) 0xFFFFu;
\r
97 public Control.ControlCollection Content {
\r
98 get { return contentFlowLayoutPanel.Controls; }
\r
101 public object UserInputValue {
\r
102 get { return userInputValue; }
\r
105 public void BuildRadioButtons(string[] options, int initialOption) {
\r
106 this.Content.Clear();
\r
108 for (int i = 0; i < options.Length; i++) {
\r
109 RadioButton optRadios = new RadioButton();
\r
110 optRadios.Text = options[i];
\r
112 optRadios.Click += HandleUserInput;
\r
113 optRadios.AutoSize = true;
\r
115 if (i == initialOption) {
\r
116 optRadios.Checked = true;
\r
117 this.userInputValue = initialOption;
\r
119 optRadios.Checked = false;
\r
122 this.Content.Add(optRadios);
\r
126 public static OptionDialog createMessageDialog(string message, string title, string mainInstruction, Icon icon)
\r
128 return createOptionDialog(message, title, mainInstruction, icon, MessageBoxButtons.OK, null, -1);
\r
131 public static OptionDialog createConfirmDialog(string message, string title, string mainInstruction, Icon icon, MessageBoxButtons buttons)
\r
133 return createOptionDialog(message, title, mainInstruction, icon, buttons, null, -1);
\r
136 public static OptionDialog createOptionDialog(string message, string title, string mainInstruction, Icon icon, MessageBoxButtons buttons, string[] options, int initialOption)
\r
138 OptionDialog dialog = new OptionDialog();
\r
139 dialog.Text = title;
\r
140 dialog.ContentText = message;
\r
141 dialog.MainInstructionText = mainInstruction;
\r
142 dialog.Image = (icon != null)? icon.ToBitmap() : null;
\r
143 dialog.Buttons = buttons;
\r
145 if (options != null) {
\r
146 dialog.BuildRadioButtons(options, initialOption);
\r
152 void OptionDialogStyleChanged(object sender, EventArgs e)
\r
154 mainInstLabel.Font = SystemFonts.CaptionFont;
\r
155 if (System.Windows.Forms.VisualStyles.VisualStyleInformation.IsEnabledByUser) {
\r
156 mainInstLabel.ForeColor = Color.FromArgb(0x003399);
\r
158 this.BackColor = SystemColors.Window;
\r
159 this.ForeColor = SystemColors.WindowText;
\r
160 separatorLabel.Visible = true;
\r
162 mainInstLabel.ForeColor = Color.Empty;
\r
164 this.BackColor = Color.Empty;
\r
165 this.ForeColor = Color.Empty;
\r
166 separatorLabel.Visible = false;
\r