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 ButtonBase button = sender as ButtonBase;
\r
32 if (textBox != null) {
\r
33 this.userInputValue = textBox.Text;
\r
35 if (button != null) {
\r
36 this.userInputValue = button.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 = iconPictureBox.Image.Size;
\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 void BuildCommandLinkButtons(string[] options, int initialOption)
\r
128 OperatingSystem os = Environment.OSVersion;
\r
130 this.Content.Clear();
\r
132 int defaultButtonWidth = this.Content.Owner.Width;
\r
133 for (int i = 0; i < options.Length; i++) {
\r
134 Button button = null;
\r
135 if (os.Platform == PlatformID.Win32NT && os.Version.Major >= 6) {
\r
136 button = new CommandLinkButton();
\r
137 string[] labelData = options[i].Split(new char[]{';'}, 2);
\r
138 button.Text = labelData[0];
\r
139 if (labelData.Length > 1 && !string.IsNullOrEmpty(labelData[1])) {
\r
140 ((CommandLinkButton) button).Note = labelData[1];
\r
141 button.Size = new Size(defaultButtonWidth, 68);
\r
143 button.Size = new Size(defaultButtonWidth, 72);
\r
146 this.Content.Add(button);
\r
148 button = new Button();
\r
149 string[] labelData = options[i].Split(new char[]{';'}, 2);
\r
150 button.Text = labelData[0];
\r
151 button.Font = new Font(button.Font.FontFamily, button.Font.Size * 1.25f, FontStyle.Underline);
\r
152 button.Size = new Size(defaultButtonWidth, button.Height);
\r
153 button.TextAlign = ContentAlignment.MiddleLeft;
\r
154 button.FlatStyle = FlatStyle.Flat;
\r
155 button.FlatAppearance.BorderSize = 0;
\r
156 button.FlatAppearance.MouseDownBackColor = SystemColors.ButtonShadow;
\r
157 button.FlatAppearance.MouseOverBackColor = button.BackColor;
\r
158 button.ForeColor = SystemColors.HotTrack;
\r
159 button.Cursor = Cursors.Hand;
\r
161 this.Content.Add(button);
\r
163 if (labelData.Length > 1 && !string.IsNullOrEmpty(labelData[1])) {
\r
164 Label label = new Label();
\r
165 label.Text = labelData[1];
\r
166 label.Margin = new Padding(10, 0, 0, 5);
\r
167 label.AutoSize = true;
\r
168 label.UseMnemonic = false;
\r
169 this.Content.Add(label);
\r
174 button.Click += HandleUserInput;
\r
175 button.DialogResult = DialogResult.OK;
\r
177 if (i == initialOption) {
\r
179 this.userInputValue = initialOption;
\r
185 public static OptionDialog createMessageDialog(string message, string title, string mainInstruction, Icon icon)
\r
187 return createOptionDialog(message, title, mainInstruction, icon, MessageBoxButtons.OK, null, -1);
\r
190 public static OptionDialog createConfirmDialog(string message, string title, string mainInstruction, Icon icon, MessageBoxButtons buttons)
\r
192 return createOptionDialog(message, title, mainInstruction, icon, buttons, null, -1);
\r
195 public static OptionDialog createOptionDialog(string message, string title, string mainInstruction, Icon icon, MessageBoxButtons buttons, string[] options, int initialOption)
\r
197 OptionDialog dialog = new OptionDialog();
\r
198 dialog.Text = title;
\r
199 dialog.ContentText = message;
\r
200 dialog.MainInstructionText = mainInstruction;
\r
201 dialog.Image = (icon != null)? icon.ToBitmap() : null;
\r
202 dialog.Buttons = buttons;
\r
204 if (options != null) {
\r
205 dialog.BuildRadioButtons(options, initialOption);
\r
211 public static OptionDialog createCommandSelectionDialog(string message, string title, string mainInstruction, Icon icon, string[] options, int initialOption)
\r
213 OptionDialog dialog = new OptionDialog();
\r
214 dialog.Text = title;
\r
215 dialog.ContentText = message;
\r
216 dialog.MainInstructionText = mainInstruction;
\r
217 dialog.Image = (icon != null)? icon.ToBitmap() : null;
\r
218 dialog.Buttons = MessageBoxButtons.OKCancel;
\r
220 if (options != null) {
\r
221 dialog.BuildCommandLinkButtons(options, initialOption);
\r
222 dialog.okButton.Visible = false;
\r
228 void OptionDialogStyleChanged(object sender, EventArgs e)
\r
230 mainInstLabel.Font = SystemFonts.CaptionFont;
\r
231 if (System.Windows.Forms.VisualStyles.VisualStyleInformation.IsEnabledByUser) {
\r
232 mainInstLabel.ForeColor = Color.FromArgb(0x003399);
\r
234 this.BackColor = SystemColors.Window;
\r
235 this.ForeColor = SystemColors.WindowText;
\r
236 separatorLabel.Visible = true;
\r
238 mainInstLabel.ForeColor = Color.Empty;
\r
240 this.BackColor = Color.Empty;
\r
241 this.ForeColor = Color.Empty;
\r
242 separatorLabel.Visible = false;
\r
246 #region CommandLinkButton
\r
248 private class CommandLinkButton : Button
\r
250 private string note = null;
\r
252 private bool isCommandLink = false;
\r
254 public CommandLinkButton()
\r
256 this.FlatStyle = FlatStyle.System;
\r
259 protected override CreateParams CreateParams {
\r
261 OperatingSystem os = Environment.OSVersion;
\r
263 CreateParams cParams = base.CreateParams;
\r
265 if (os.Platform == PlatformID.Win32NT && os.Version.Major >= 6) {
\r
266 cParams.Style |= 0x0000000E; // BS_COMMANDLINK
\r
267 this.isCommandLink = true;
\r
269 this.Padding = new Padding(5);
\r
275 public string Note {
\r
277 if (this.isCommandLink) {
\r
279 //SendMessage(hWnd, BCM_SETNOTE, NULL, (PCWSTR)value);
\r
280 NativeMethods.SendMessage(this.Handle, 0x00001609, IntPtr.Zero, System.Runtime.InteropServices.Marshal.StringToHGlobalAuto(value));
\r
283 get { return this.note; }
\r