SoFunction
Updated on 2025-03-07

Detailed explanation and use of messagebox of c# message box

Detailed explanation and use of messagebox for C# message box

The message dialog box is displayed using the show method of the messagebox object. The MessageBox object is part of the namespace. Show is a static method, which means that you can use this method without creating an instance based on the MessageBox class object. Moreover, this method can be overloaded, that is, the method can have different parameter list forms.

Return result:DialogResult dr1=(text,caption,buttons,icon,defaultbutton,option);

No value is returned:(text,caption,buttons,icon);

Parameters must be output in the above order

1.Text: Set the prompt text statement in the message dialog box. It must be of String type
2.Caption: Optional parameters, set the title of the message dialog box, must be string type
3. Buttons: optional parameters, set which buttons are displayed in the message dialog box
4. Icon: Optional parameters, set which icon to display in the message dialog box
5. Defaultbutton: optional parameters, set which button in the message dialog box is activated by default
6. Optional parameters, set some special options for the message dialog box, such as text alignment, specifying the reading order, and whether to write messages to the system log

Button enumeration constants and meanings

Ok  There is only the OK button in the message box
 OkCancel  There are only "OK" and "Cancel" buttons in the message box
 YesNo  There are only "Yes" and "No" buttons in the message box
 YesNoCancel  There are "Yes", "No" and "Cancel" buttons in the message box
 RetryCancel  There are "Retry" and "Cancel" buttons in the message box
 AbortRetryIgnore  There are "Abort", "Retry" and "Ignore" buttons in the message box
 constant  Function and significance

Icon enumeration constants and meanings

 Enumeration constants  Functional significance
 Error  There is a symbol in the message box, composed of a circle with a red background and a white X in it
 Asterisk  The symbol is composed of a circle and its lowercase letter i
 Exclamation  The symbol consists of a triangle on a yellow background and one of the exclamation marks.
 Hand  The symbol consists of a circle on a red background with white x in it
 Question  The symbol consists of a circle and a question mark in it
 None  The message box does not contain symbols
 Information  The symbol is composed of a circle and its lowercase letter i
 Stop  The symbol is composed of a circle on a red background with a white X in it
Warning The symbol is composed of a triangle with a yellow background and one of the exclamation marks.

The return value of the message dialog box is the member, and the enumeration constants and meanings are as follows

 Abort  The return value of the message box is "Abort", that is, the "Abort" button is clicked
 Cancel  The return value of the message box is "Cancel", that is, the "Cancel" button is clicked
 Ignore  The return value of the message box is "Ignore", that is, the "Ignore" button is clicked
 No

 The return value of the message box is "No" (No), that is, the "No" button is clicked

 Ok  The return value of the message box is "Ok", that is, the "Ok" button is clicked
 Retry  The return value of the message box is "Retry", that is, the "Retry" button is clicked
 None  The message box does not have any return value, i.e. no button is clicked
 Yes  The return value of the message box is "Yes" (Yes), that is, the "Yes" button is clicked
   

 

use:

1、 /* if (flag)
       {
         DialogResult diagorel = (this, "Please inpult again,your message is empty!", "Information cue", , );
         switch (diagorel)
         {
           case :
              = "";
              = "";
             break;
           case :
             break;


         }
       }*/

2. This is the easiest way

if( ( "Are you sure to submit?", "hint",  ) ==  )
      {
        Program running code.......
      }

Thank you for reading, I hope it can help you. Thank you for your support for this site!