Call the message dialog box in C # and get its return value
Source: Internet
Author: User
The dialog box is different from the VB can directly use MsgBox to get message box return value, in C # you need to use DialogResult type of variables, from the MessageBox.Show () method to accept the message dialog box return value. As for the return value of MessageBox.Show () is yes, No, OK or cancel, you need to set the selection button that it can display in the show () method. The following sample code can refer to:
Initializes the variables to the MessageBox.Show method.
String message = ' You did ' not enter a server name. Cancel this operation? ";
String caption = "No Server Name Specified";
MessageBoxButtons buttons = Messageboxbuttons.yesno;
DialogResult result;
Displays the MessageBox.
result = MessageBox.Show (this, message, caption, buttons,
Messageboxicon.question, Messageboxdefaultbutton.button1,
Messageboxoptions.rightalign);
if (result = = Dialogresult.yes)
{
Do your action here.
}
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.