What buttons need to be displayed in a message box where OK and cancel are displayed
MessageBoxButtons Messbutton = Messageboxbuttons.okcancel;
"Are you sure you want to exit?" "Is the display information for the dialog box," Exit System "is the title of the dialog box
By default, such as MessageBox.Show ("Are you sure you want to exit?") ") displays only one OK button.
DialogResult dr = MessageBox.Show ("OK to exit?", "Exit System", Messbutton);
if (dr = = DialogResult.OK)//If Click "OK" button
{
......
}
else//If you click the "Cancel" button
{
......
}
MessageBoxButtons specifies several constants to define which buttons will appear on MessageBox (from MSDN)
MessageBoxButtons Member:
Description of Member name
The Abortretryignore message box contains the abort, retry, and Ignore buttons.
The OK message box contains the OK button. Default
The Okcancel message box contains the OK and Cancel buttons. (as shown in the previous example)
The Retrycancel message box contains the retry and Cancel buttons.
The YESNO message box contains the Yes and no buttons.
The Yesnocancel message box contains Yes, no, and Cancel buttons.
For example:
MessageBoxButtons Messbutton = Messageboxbuttons.okcancel;
DialogResult dr = MessageBox.Show ("OK to exit?", "Exit System", Messbutton);
if (dr = = DialogResult.OK)
{
This. Close ();
}
Pop-up OK, cancel the prompt box, if click Confirmation Program exit. Cancel closes the prompt box.