MessageBox Options : MessageBox « GUI Windows Form « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » GUI Windows Form » MessageBoxScreenshots 
MessageBox Options
MessageBox Options


   using System;
   using System.Drawing;
   using System.Collections;
   using System.ComponentModel;
   using System.Windows.Forms;
   using System.Data;

   public class RadioButtonsTest : System.Windows.Forms.Form {
      private System.Windows.Forms.Label promptLabel;
      private System.Windows.Forms.Label displayLabel;
      private System.Windows.Forms.Button displayButton;

      private System.Windows.Forms.RadioButton questionButton;
      private System.Windows.Forms.RadioButton informationButton;
      private System.Windows.Forms.RadioButton exclamationButton;
      private System.Windows.Forms.RadioButton errorButton;
      private System.Windows.Forms.RadioButton retryCancelButton;
      private System.Windows.Forms.RadioButton yesNoButton;
      private System.Windows.Forms.RadioButton yesNoCancelButton;
      private System.Windows.Forms.RadioButton okCancelButton;
      private System.Windows.Forms.RadioButton okButton;
      private System.Windows.Forms.RadioButton abortRetryIgnoreButton;

      private System.Windows.Forms.GroupBox iconTypeGroupBox;
      private System.Windows.Forms.GroupBox buttonTypeGroupBox;

      private MessageBoxIcon iconType = MessageBoxIcon.Error;
      private MessageBoxButtons buttonType = MessageBoxButtons.OK;
      
      public RadioButtonsTest() {
         InitializeComponent();
      }
      private void InitializeComponent() {
         this.informationButton = new System.Windows.Forms.RadioButton();
         this.buttonTypeGroupBox = new System.Windows.Forms.GroupBox();
         this.retryCancelButton = new System.Windows.Forms.RadioButton();
         this.yesNoButton = new System.Windows.Forms.RadioButton();
         this.yesNoCancelButton = new System.Windows.Forms.RadioButton();
         this.abortRetryIgnoreButton = new System.Windows.Forms.RadioButton();
         this.okCancelButton = new System.Windows.Forms.RadioButton();
         this.okButton = new System.Windows.Forms.RadioButton();
         this.iconTypeGroupBox = new System.Windows.Forms.GroupBox();
         this.questionButton = new System.Windows.Forms.RadioButton();
         this.exclamationButton = new System.Windows.Forms.RadioButton();
         this.errorButton = new System.Windows.Forms.RadioButton();
         this.displayLabel = new System.Windows.Forms.Label();
         this.displayButton = new System.Windows.Forms.Button();
         this.promptLabel = new System.Windows.Forms.Label();
         this.buttonTypeGroupBox.SuspendLayout();
         this.iconTypeGroupBox.SuspendLayout();
         this.SuspendLayout();

         // 
         // informationButton
         // 
         this.informationButton.Location = new System.Drawing.Point16104 );
         this.informationButton.Name = "informationButton";
         this.informationButton.Size = new System.Drawing.Size10023 );
         this.informationButton.TabIndex = 4;
         this.informationButton.Text = "Information";
         this.informationButton.CheckedChanged += new System.EventHandler(this.iconType_CheckedChanged );

         // 
         // buttonTypeGroupBox
         // 
         this.buttonTypeGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
               this.retryCancelButton,this.yesNoButton,this.yesNoCancelButton,
               this.abortRetryIgnoreButton,this.okCancelButton,this.okButton } );
         this.buttonTypeGroupBox.Location =new System.Drawing.Point1656 );
         this.buttonTypeGroupBox.Name = "buttonTypeGroupBox";
         this.buttonTypeGroupBox.Size =new System.Drawing.Size152272 );
         this.buttonTypeGroupBox.TabIndex = 0;
         this.buttonTypeGroupBox.TabStop = false;
         this.buttonTypeGroupBox.Text = "Button Type";

         // 
         // retryCancelButton
         // 
         this.retryCancelButton.Location =new System.Drawing.Point16224 );
         this.retryCancelButton.Name = "retryCancelButton";
         this.retryCancelButton.Size =new System.Drawing.Size10023 );
         this.retryCancelButton.TabIndex = 4;
         this.retryCancelButton.Text = "RetryCancel";

         // all radio buttons for button types are registered
         // to buttonType_CheckedChanged event handler
         this.retryCancelButton.CheckedChanged +=new System.EventHandler(this.buttonType_CheckedChanged );

         // 
         // yesNoButton
         // 
         this.yesNoButton.Location = new System.Drawing.Point16184 );
         this.yesNoButton.Name = "yesNoButton";
         this.yesNoButton.Size = new System.Drawing.Size10023 );
         this.yesNoButton.TabIndex = 0;
         this.yesNoButton.Text = "YesNo";
         this.yesNoButton.CheckedChanged +=new System.EventHandler(this.buttonType_CheckedChanged );

         // 
         // yesNoCancelButton
         // 
         this.yesNoCancelButton.Location =new System.Drawing.Point16144 );
         this.yesNoCancelButton.Name = "yesNoCancelButton";
         this.yesNoCancelButton.Size =new System.Drawing.Size10023 );
         this.yesNoCancelButton.TabIndex = 3;
         this.yesNoCancelButton.Text = "YesNoCancel";
         this.yesNoCancelButton.CheckedChanged +=new System.EventHandler(this.buttonType_CheckedChanged );

         // 
         // abortRetryIgnoreButton
         // 
         this.abortRetryIgnoreButton.Location =new System.Drawing.Point16104 );
         this.abortRetryIgnoreButton.Name ="abortRetryIgnoreButton";
         this.abortRetryIgnoreButton.Size =new System.Drawing.Size12023 );
         this.abortRetryIgnoreButton.TabIndex = 2;
         this.abortRetryIgnoreButton.Text = "AbortRetryIgnore";
         this.abortRetryIgnoreButton.CheckedChanged += new System.EventHandler(this.buttonType_CheckedChanged );

         // 
         // okCancelButton
         // 
         this.okCancelButton.Location =new System.Drawing.Point1664 );
         this.okCancelButton.Name = "okCancelButton";
         this.okCancelButton.Size =new System.Drawing.Size10023 );
         this.okCancelButton.TabIndex = 1;
         this.okCancelButton.Text = "OKCancel";
         this.okCancelButton.CheckedChanged +=new System.EventHandler(this.buttonType_CheckedChanged );

         // 
         // okButton
         // 
         this.okButton.Checked = true;
         this.okButton.Location =new System.Drawing.Point1624 );
         this.okButton.Name = "okButton";
         this.okButton.Size =new System.Drawing.Size10023 );
         this.okButton.TabIndex = 0;
         this.okButton.TabStop = true;
         this.okButton.Text = "OK";
         this.okButton.CheckedChanged +=new System.EventHandler(this.buttonType_CheckedChanged );

         // 
         // iconTypeGroupBox
         // 
         this.iconTypeGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
               this.questionButton,this.informationButton,this.exclamationButton,
               this.errorButton } );
         this.iconTypeGroupBox.Location =new System.Drawing.Point20056 );
         this.iconTypeGroupBox.Name = "iconTypeGroupBox";
         this.iconTypeGroupBox.Size =new System.Drawing.Size136176 );
         this.iconTypeGroupBox.TabIndex = 1;
         this.iconTypeGroupBox.TabStop = false;
         this.iconTypeGroupBox.Text = "Icon";

         // 
         // questionButton
         // 
         this.questionButton.Location =new System.Drawing.Point16144 );
         this.questionButton.Name = "questionButton";
         this.questionButton.Size =new System.Drawing.Size10023 );
         this.questionButton.TabIndex = 0;
         this.questionButton.Text = "Question";

         // all radio buttons for icon types are registered
         // to iconType_CheckedChanged event handler
         this.questionButton.CheckedChanged +=new System.EventHandler(this.iconType_CheckedChanged );

         // 
         // exclamationButton
         // 
         this.exclamationButton.Location =new System.Drawing.Point1664 );
         this.exclamationButton.Name = "exclamationButton";
         this.exclamationButton.Size =new System.Drawing.Size10423 );
         this.exclamationButton.TabIndex = 2;
         this.exclamationButton.Text = "Exclamation";
         this.exclamationButton.CheckedChanged +=new System.EventHandler(this.iconType_CheckedChanged );

         // 
         // errorButton
         // 
         this.errorButton.Location =new System.Drawing.Point1624 );
         this.errorButton.Name = "errorButton";
         this.errorButton.Size =new System.Drawing.Size10023 );
         this.errorButton.TabIndex = 1;
         this.errorButton.Text = "Error";
         this.errorButton.CheckedChanged +=new System.EventHandler(this.iconType_CheckedChanged );

         // 
         // displayLabel
         // 
         this.displayLabel.Location =new System.Drawing.Point200304 );
         this.displayLabel.Name = "displayLabel";
         this.displayLabel.Size = 
            new System.Drawing.Size13624 );
         this.displayLabel.TabIndex = 4;

         // 
         // displayButton
         // 
         this.displayButton.Location =new System.Drawing.Point200240 );
         this.displayButton.Name = "displayButton";
         this.displayButton.Size =new System.Drawing.Size13648 );
         this.displayButton.TabIndex = 3;
         this.displayButton.Text = "Display";
         this.displayButton.Click +=new System.EventHandlerthis.displayButton_Click );

         // 
         // promptLabel
         // 
         this.promptLabel.Font =new System.Drawing.Font("Microsoft Sans Serif"9.5F
            System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,( ( System.Byte )( ) ) );
         this.promptLabel.Location =new System.Drawing.Point816 );
         this.promptLabel.Name = "promptLabel";
         this.promptLabel.Size =new System.Drawing.Size34424 );
         this.promptLabel.TabIndex = 5;
         this.promptLabel.Text = "Choose the type of MessageBox you would like to display!";

         // 
         // RadioButtonsTest
         // 
         this.AutoScaleBaseSize =new System.Drawing.Size513 );
         this.ClientSize =new System.Drawing.Size360341 );
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
               this.promptLabel,this.displayLabel,this.displayButton,
               this.iconTypeGroupBox,this.buttonTypeGroupBox } );
         this.Name = "RadioButtonsTest";
         this.Text = "Demonstrating RadioButtons";
         this.buttonTypeGroupBox.ResumeLayoutfalse );
         this.iconTypeGroupBox.ResumeLayoutfalse );
         this.ResumeLayoutfalse );

      }

      [STAThread]
      static void Main() 
      {
         Application.Runnew RadioButtonsTest() );
      }

      private void buttonType_CheckedChanged(object sender, System.EventArgs e )
      {
         if sender == okButton )
            buttonType = MessageBoxButtons.OK;
         else if sender == okCancelButton )
            buttonType = MessageBoxButtons.OKCancel;
         else if sender == abortRetryIgnoreButton )
            buttonType = MessageBoxButtons.AbortRetryIgnore;
         else if sender == yesNoCancelButton )
            buttonType = MessageBoxButtons.YesNoCancel;
         else if sender == yesNoButton )
            buttonType = MessageBoxButtons.YesNo;
         else
            buttonType = MessageBoxButtons.RetryCancel;
      }

      private void iconType_CheckedChanged(object sender, System.EventArgs e )
      {
         if sender == errorButton )
            iconType = MessageBoxIcon.Error;
         else if sender == exclamationButton )
            iconType = MessageBoxIcon.Exclamation;
         else if sender == informationButton 
            iconType = MessageBoxIcon.Information;
         else
            iconType = MessageBoxIcon.Question;
      }
      protected void displayButton_Click(object sender, System.EventArgs e )
      {
         DialogResult result =MessageBox.Show"This is Your Custom MessageBox."
            "Custom MessageBox", buttonType, iconType, 0);
         switch result ) {
            case DialogResult.OK: 
               displayLabel.Text = "OK was pressed."
               break;

            case DialogResult.Cancel: 
               displayLabel.Text = "Cancel was pressed."
               break;

            case DialogResult.Abort: 
               displayLabel.Text = "Abort was pressed."
               break;

            case DialogResult.Retry: 
               displayLabel.Text = "Retry was pressed."
               break;

            case DialogResult.Ignore: 
               displayLabel.Text = "Ignore was pressed."
               break;

            case DialogResult.Yes: 
               displayLabel.Text = "Yes was pressed."
               break;

            case DialogResult.No: 
               displayLabel.Text = "No was pressed."
               break;
         }
      }
   


           
       
Related examples in the same category
1. Display Question messagebox and check its resultDisplay Question messagebox and check its result
2. MessageBox with OK button and information iconMessageBox with OK button and information icon
3. Message box builderMessage box builder
4. Information message boxInformation message box
5. A message boxA message box
w__w__w___.ja_v___a___2___s__.c_om___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.