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 | |
|
|
|
|
|
|
|
|
|
|
|
|
Icon Enumeration Constants and Their Significance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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!