我想要它,以便一个名为“退出”的菜单项显示一个消息框,询问用户是否真的希望退出,但无论他们单击是还是否,它仍然会退出程序。
private void Exit_Click(object sender, EventArgs e)
{
// Shows a prompt asking the user if they really want to exit
DialogResult dQuit;
dQuit = MessageBox.Show("Do you really wish to exit?",
"Exit?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
// If 'Yes' button is clicked, close the program
if (dQuit == DialogResult.Yes)
{
Application.Exit();
}
else
{
// Else, close the dialog box and return to the menu screen
this.DialogResult = System.Windows.Forms.DialogResult.No;
}
}