我想要一个名为'Exit'的菜单栏项目会弹出一个MessageBox,询问用户他们是否真的想退出,但不管他们是否点击Yes或No,它仍然会退出程序。MessageBox - 两个按钮做同样的事情?
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;
}
}
为什么...你可以有? messagebox说退出一个确定的按钮,如果这真的是你需要的 – Sayse 2013-03-15 12:15:48
我不知道你为什么要这样的行为。但在那种情况下,为什么要显示一个MessageBox呢?只需退出而不询问用户。 – Otiel 2013-03-15 12:16:16
调用'ShowDialog()'这个对话框的代码是什么样的? – 2013-03-15 12:16:37