I have a problem with my confirmation messages..
I have two MessageBox, the first one ask “Do you want to quit?”
The second one, ask “Are you sure!?”
My problem is that if I choose yes when the first MessageBox “Do you want to quit?” show up, the second MessageBox will still appear..
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
var confirmationBox = MessageBox.Show(@"Do you want to quit", @"Title",
MessageBoxButtons.YesNo);
var confirmationBox2 = MessageBox.Show(@"Are you sure?", @"", MessageBoxButtons.YesNo);
if (confirmationBox == DialogResult.Yes)
{
if (confirmationBox2 == DialogResult.No)
{
e.Cancel = true;
}
}
}
}
}
Don’t show the second message box until you have inspected the results of the first:
P.S. annoying your users with dialogs such as these are annoying; consider not doing this unless there’s a real compelling reason that they shouldn’t close right now (i.e. in the middle of an operation that would be left in an invalid state, or have unsaved data).