Detailed Explanation and Application of c Message Prompt Box messagebox

  • 2021-12-11 08:39:37
  • OfStack

Detailed Explanation and Application of C # Message Prompt Box messagebox

The message dialog box is displayed with the show method of the messagebox object. The MessageBox object is part of the namespace System. Windows. Forms, and Show is a static method, meaning that it can be used without creating an instance based on an object of the MessageBox class. Moreover, the method can be overloaded, that is, the method can have different parameter list forms.

Return results: DialogResult dr1=MessageBox. Show (text, caption, buttons, icon, defaultbutton, option);

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

Parameters must be output in the above order

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

Button Enumeration Constants and Their Significance

Ok  消息框中只有"确定"按钮
 OkCancel  消息框中只有"确定"和"取消"按钮
 YesNo  消息框中只有"是"和"否"按钮
 YesNoCancel  消息框中有"是","否"和"取消"按钮
 RetryCancel  消息框中有"重试"和"取消"按钮
 AbortRetryIgnore  消息框中有"中止","重试"和"忽略"按钮
 常量  功能及意义

Icon Enumeration Constants and Their Significance

 枚举常量  功能意义
 Error  消息框中有1个符号,由1个红色背景的圆圈及其中的白色X组成
 Asterisk  该符号是由1个圆圈及其中的小写字母i组成
 Exclamation  该符号由1个黄色背景的3角形及其中的1个叹号组成
 Hand  该符号由1个红色背景的圆圈及其中的白色x组成
 Question  该符号由1个圆圈及其中的1个问号组成
 None  消息框中不包含符号
 Information  该符号是由1个圆圈及其中的小写字母i组成
 Stop  该符号是由1个红色背景的圆圈及其中的白色X组成
Warning 该符号是由1个黄色背景的3角形及其中的1个叹号组成

The return value of the message dialog box is a member of System. Windows. Forms. DialogResult. The enumeration constants and their meanings are as follows

 Abort  消息框的返回值是"中止"(Abort),即单击了"中止"按钮
 Cancel  消息框的返回值是"取消"(Cancel),即单击了"取消"按钮
 Ignore  消息框的返回值是"忽略"(Ignore),即单击了"忽略"按钮
 No

 消息框的返回值是"否"(No),即单击了"否"按钮

 Ok  消息框的返回值是"确定"(Ok),即单击了"确定"按钮
 Retry  消息框的返回值是"重试"(Retry),即单击了"重试"按钮
 None  消息框没有任何返回值,即没有单击任何按钮
 Yes  消息框的返回值是"是"(Yes),即单击了"是"按钮
   

Use:


1 ,  /* if (flag)
       {
         DialogResult diagorel = MessageBox.Show(this, "Please inpult again,your message is empty!", "Information cue", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
         switch (diagorel)
         {
           case DialogResult.Retry:
             this.username.Text = "";
             this.password.Text = "";
             break;
           case DialogResult.Cancel:
             break;


         }
       }*/

2. This is the easiest way to do it


if( MessageBox.Show( " Are you sure to submit? ", " Prompt ", MessageBoxButtons.YesNo ) == DialogResult.Yes )
      {
         Program running code .......
      }

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: