Detailed description of the use of the C # message prompt box MessageBox

Source: Internet
Author: User
This article mainly introduces the C # message box MessageBox in detail and the use of relevant information, the need for friends can refer to the following

C # message prompt box in detail and use

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, which means that you do not need to create an instance based on the MessageBox class object to use this method. And the method can be overloaded, that is, the method can have a different parameter list form.

Results returned:DialogResult dr1=messagebox.show (text,caption,buttons,icon,defaultbutton,option);

does not return any value:MessageBox.Show (Text,caption,buttons,icon);

Parameters must be output in the order above

1,text: Sets the prompt text statement in the message dialog box. Must be of type string
2,caption: Optional parameter, set the caption of the message dialog box, must be a string type
3,buttons: Optional parameters 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, set the message dialog box which button is activated by default
6,option Optional parameters, set 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 meanings

Ok Only the OK button in the message box
Okcancel Only the OK and Cancel buttons in the message box
YesNo Only "yes" and "no" buttons in message boxes
Yesnocancel "Yes", "No" and "Cancel" buttons in the message box
Retrycancel There are "Retry" and "Cancel" buttons in the message box
Abortretryignore "Abort", "Retry" and "Ignore" buttons in the message box
Constant Function and significance

Icon enumeration constants and their meanings

Enumeration constants Functional significance
Error A message box has a symbol that consists of a red background circle and a white x in it
Asterisk The symbol is made up of a circle and the lowercase letter I
Exclamation The symbol consists of a triangle with a yellow background and an exclamation mark in it.
Hand The symbol consists of a circle with a red background and a 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 made up of a circle and the lowercase letter I
Stop The symbol is made up of a red background circle and a white x in it
Warning The symbol is made up of a yellow background triangle and an exclamation mark in it.

The return value of the message dialog box is a member of the System.Windows.Forms.DialogResult, and the enumeration constants and meanings are the following table

Abort The return value of the message box is abort (abort), that is, the Abort button is clicked
Cancel The return value of the message box is cancel (cancel), that is, the Cancel button is clicked
Ignore The return value of the message box is "Ignore" (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 (OK), that is, the OK button is clicked
Retry The return value of the message box is "Retry" (Retry), that is, the Retry button was clicked
None The message box does not have any return value, that is, 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 = 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, the simplest way is this

if (MessageBox.Show ("OK to commit?"). "," hint ", messageboxbuttons.yesno) = = Dialogresult.yes)      {        program run code ...      }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.