// Constructor. public MessageBoxForm(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) { // Set the message box's caption. if(caption != null) { Text = caption; } else { Text = String.Empty; } // Make the borders suitable for a dialog box. FormBorderStyle = FormBorderStyle.FixedDialog; MinimizeBox = false; ShowInTaskbar = false; // Create the layout areas. vbox = new VBoxLayout(); hbox = new HBoxLayout(); buttonBox = new ButtonBoxLayout(); vbox.Controls.Add(hbox); vbox.Controls.Add(buttonBox); vbox.StretchControl = hbox; buttonBox.UniformSize = true; vbox.Dock = DockStyle.Fill; Controls.Add(vbox); // Create a control to display the message box icon. this.icon = LoadIcon(icon); if(this.icon != null) { iconControl = new Control(); iconControl.ClientSize = this.icon.Size; iconControl.TabStop = false; hbox.Controls.Add(iconControl); } // Create the label containing the message text. textLabel = new Label(); textLabel.TextAlign = ContentAlignment.MiddleLeft; textLabel.TabStop = false; if(text != null) { textLabel.Text = text; } else { textLabel.Text = String.Empty; } hbox.Controls.Add(textLabel); // Determine the number and names of the message box buttons. this.buttons = buttons; switch(buttons) { case MessageBoxButtons.OK: default: { button1 = new Button(); button1.Text = S._("SWF_MessageBox_OK", "OK"); button2 = null; button3 = null; hasCancel = true; // Can always cancel an OK dialog. } break; case MessageBoxButtons.OKCancel: { button1 = new Button(); button2 = new Button(); button1.Text = S._("SWF_MessageBox_OK", "OK"); button2.Text = S._("SWF_MessageBox_Cancel", "Cancel"); button3 = null; hasCancel = true; } break; case MessageBoxButtons.AbortRetryIgnore: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button3 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Abort", "&Abort"); button2.Text = S._("SWF_MessageBox_Retry", "&Retry"); button3.Text = S._("SWF_MessageBox_Ignore", "&Ignore"); hasCancel = false; } break; case MessageBoxButtons.YesNoCancel: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button3 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Yes", "&Yes"); button2.Text = S._("SWF_MessageBox_No", "&No"); button3.Text = S._("SWF_MessageBox_Cancel", "Cancel"); hasCancel = true; } break; case MessageBoxButtons.YesNo: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Yes", "&Yes"); button2.Text = S._("SWF_MessageBox_No", "&No"); button3 = null; hasCancel = false; } break; case MessageBoxButtons.RetryCancel: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Retry", "&Retry"); button2.Text = S._("SWF_MessageBox_Cancel", "Cancel"); button3 = null; hasCancel = true; } break; } // Add the buttons to the control. buttonBox.Controls.Add(button1); if(button2 != null) { buttonBox.Controls.Add(button2); } if(button3 != null) { buttonBox.Controls.Add(button3); } // Set the "Accept" and "Cancel" buttons. Button acceptButton = null; if(hasCancel) { if(button3 != null) { CancelButton = button3; } else if(button2 != null) { CancelButton = button2; } } switch(defaultButton) { case MessageBoxDefaultButton.Button1: default: { acceptButton = button1; } break; case MessageBoxDefaultButton.Button2: { if(button2 != null) { acceptButton = button2; } else { acceptButton = button1; } } break; case MessageBoxDefaultButton.Button3: { if(button3 != null) { acceptButton = button3; } else if(button2 != null) { acceptButton = button2; } else { acceptButton = button1; } } break; } AcceptButton = acceptButton; // Hook up the events for the form. button1.Click += new EventHandler(Button1Clicked); if(button2 != null) { button2.Click += new EventHandler(Button2Clicked); } if(button3 != null) { button3.Click += new EventHandler(Button3Clicked); } Closing += new CancelEventHandler(CloseRequested); if(iconControl != null) { iconControl.Paint += new PaintEventHandler(PaintIcon); } // Set the initial message box size to the vbox's recommended. ClientSize = vbox.RecommendedSize; }
// Constructor. public MessageBoxForm(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) { // Set the message box's caption. if (caption != null) { Text = caption; } else { Text = String.Empty; } // Make the borders suitable for a dialog box. FormBorderStyle = FormBorderStyle.FixedDialog; MinimizeBox = false; ShowInTaskbar = false; // Create the layout areas. vbox = new VBoxLayout(); hbox = new HBoxLayout(); buttonBox = new ButtonBoxLayout(); vbox.Controls.Add(hbox); vbox.Controls.Add(buttonBox); vbox.StretchControl = hbox; buttonBox.UniformSize = true; vbox.Dock = DockStyle.Fill; Controls.Add(vbox); // Create a control to display the message box icon. this.icon = LoadIcon(icon); if (this.icon != null) { iconControl = new Control(); iconControl.ClientSize = this.icon.Size; iconControl.TabStop = false; hbox.Controls.Add(iconControl); } // Create the label containing the message text. textLabel = new Label(); textLabel.TextAlign = ContentAlignment.MiddleLeft; textLabel.TabStop = false; if (text != null) { textLabel.Text = text; } else { textLabel.Text = String.Empty; } hbox.Controls.Add(textLabel); // Determine the number and names of the message box buttons. this.buttons = buttons; switch (buttons) { case MessageBoxButtons.OK: default: { button1 = new Button(); button1.Text = S._("SWF_MessageBox_OK", "OK"); button2 = null; button3 = null; hasCancel = true; // Can always cancel an OK dialog. } break; case MessageBoxButtons.OKCancel: { button1 = new Button(); button2 = new Button(); button1.Text = S._("SWF_MessageBox_OK", "OK"); button2.Text = S._("SWF_MessageBox_Cancel", "Cancel"); button3 = null; hasCancel = true; } break; case MessageBoxButtons.AbortRetryIgnore: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button3 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Abort", "&Abort"); button2.Text = S._("SWF_MessageBox_Retry", "&Retry"); button3.Text = S._("SWF_MessageBox_Ignore", "&Ignore"); hasCancel = false; } break; case MessageBoxButtons.YesNoCancel: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button3 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Yes", "&Yes"); button2.Text = S._("SWF_MessageBox_No", "&No"); button3.Text = S._("SWF_MessageBox_Cancel", "Cancel"); hasCancel = true; } break; case MessageBoxButtons.YesNo: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Yes", "&Yes"); button2.Text = S._("SWF_MessageBox_No", "&No"); button3 = null; hasCancel = false; } break; case MessageBoxButtons.RetryCancel: { button1 = SetHotkeyPrefix(new Button()); button2 = SetHotkeyPrefix(new Button()); button1.Text = S._("SWF_MessageBox_Retry", "&Retry"); button2.Text = S._("SWF_MessageBox_Cancel", "Cancel"); button3 = null; hasCancel = true; } break; } // Add the buttons to the control. buttonBox.Controls.Add(button1); if (button2 != null) { buttonBox.Controls.Add(button2); } if (button3 != null) { buttonBox.Controls.Add(button3); } // Set the "Accept" and "Cancel" buttons. Button acceptButton = null; if (hasCancel) { if (button3 != null) { CancelButton = button3; } else if (button2 != null) { CancelButton = button2; } } switch (defaultButton) { case MessageBoxDefaultButton.Button1: default: { acceptButton = button1; } break; case MessageBoxDefaultButton.Button2: { if (button2 != null) { acceptButton = button2; } else { acceptButton = button1; } } break; case MessageBoxDefaultButton.Button3: { if (button3 != null) { acceptButton = button3; } else if (button2 != null) { acceptButton = button2; } else { acceptButton = button1; } } break; } AcceptButton = acceptButton; // Hook up the events for the form. button1.Click += new EventHandler(Button1Clicked); if (button2 != null) { button2.Click += new EventHandler(Button2Clicked); } if (button3 != null) { button3.Click += new EventHandler(Button3Clicked); } Closing += new CancelEventHandler(CloseRequested); if (iconControl != null) { iconControl.Paint += new PaintEventHandler(PaintIcon); } // Set the initial message box size to the vbox's recommended. ClientSize = vbox.RecommendedSize; }
// Constructor. public NewFolderForm(String currentDirectory) { // Record the current directory to create the folder in. this.currentDirectory = currentDirectory; // Set the dialog box's caption. Text = S._("SWF_FileDialog_NewFolder"); // Make the borders suitable for a dialog box. FormBorderStyle = FormBorderStyle.FixedDialog; MinimizeBox = false; ShowInTaskbar = false; // Create the layout areas. vbox = new VBoxLayout(); hbox = new HBoxLayout(); vbox2 = new VBoxLayout(); buttonBox = new ButtonBoxLayout(); vbox.Controls.Add(hbox); vbox.Controls.Add(buttonBox); vbox.StretchControl = hbox; buttonBox.UniformSize = true; vbox.Dock = DockStyle.Fill; Controls.Add(vbox); // Create a control to display the message box icon. this.icon = new Icon(typeof(MessageBox), "question.ico"); iconControl = new Control(); iconControl.ClientSize = this.icon.Size; iconControl.TabStop = false; hbox.Controls.Add(iconControl); hbox.Controls.Add(vbox2); // Create the label containing the message text. textLabel = new Label(); textLabel.TextAlign = ContentAlignment.MiddleLeft; textLabel.TabStop = false; textLabel.Text = S._("SWF_FileDialog_NewFolderName"); vbox2.Controls.Add(textLabel); // Create the text box for the folder name entry. textBox = new TextBox(); vbox2.Controls.Add(textBox); // Create the buttons. button1 = new Button(); button2 = new Button(); button1.Text = S._("SWF_MessageBox_OK", "OK"); button2.Text = S._("SWF_MessageBox_Cancel", "Cancel"); buttonBox.Controls.Add(button1); buttonBox.Controls.Add(button2); AcceptButton = button1; CancelButton = button2; // Hook up the events for the form. button1.Click += new EventHandler(Button1Clicked); button2.Click += new EventHandler(Button2Clicked); Closing += new CancelEventHandler(CloseRequested); iconControl.Paint += new PaintEventHandler(PaintIcon); // Set the initial message box size to the vbox's // recommended size. Size size = vbox.RecommendedSize; if(size.Width < 350) { size.Width = 350; } ClientSize = size; MinimumSize = size; MaximumSize = size; }