if (MessageBox.Show("Are you sure?", "Exit Application?",
MessageBoxButtons.YesNo) == DialogResult.No)
{
// ignore it
}
else
{
// shutdown code goes here
}
There's an MSDN example here.
문제
Upon closing the form by clicking on the button I created named 'Exit' I want it to display a messagebox asking the user "Are you sure you want to exit?" I don't know the syntax for it, can someone help me please? Thanks
해결책 2
if (MessageBox.Show("Are you sure?", "Exit Application?",
MessageBoxButtons.YesNo) == DialogResult.No)
{
// ignore it
}
else
{
// shutdown code goes here
}
There's an MSDN example here.
다른 팁
You need to look at the Form. closing event. You can place your message box there and then if you want to abort the form closing set e.cancel = true.
Have you tried something like:
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
if(MessageBox.Show("Exit Application?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Close();
}
}