The first
MessageBox.Show("Please enter the user name"); //Prompt box
the second
//Which buttons need to be displayed in the message box, "OK" and "Cancel" are displayed here
MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
//"Are you sure you want to exit?" is the display information of the dialog box, and "Exit the system" is the title of the dialog box
//By default, such as MessageBox.Show("Are you sure you want to exit?") only shows an "OK" button.
DialogResult dr = MessageBox.Show("Are you sure you want to exit?", "Exit system", messButton);
if (dr == DialogResult.OK)//If the "OK" button is clicked
{
……
}
else//If the "Cancel" button is clicked
{
……
}
MessageBoxButtons specifies several constants that define which buttons will be displayed on the MessageBox (from MSDN)
MessageBoxButtons members:
Member Name Description
The AbortRetryIgnore message box contains Abort, Retry, and Ignore buttons.
The OK message box contains an OK button. (Default)
The OKCancel message box contains OK and Cancel buttons. (Example above)
The RetryCancel message box contains Retry and Cancel buttons.
The YesNo message box contains Yes and No buttons.
YesNoCancel message box contains Yes, No, and Cancel buttons