The problem is that the messagebox with \"sure you wanna close?\" does pop up, but when I click \"no\", it still proceeds to close the program. Any suggestions? Here\'s my c
protected Boolean CanClose(Boolean CanIt)
{
if(MessageBox.Show("Wanna close?", "Cancel Installer", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ShowDialog() == DialogResult.Yes)
{
// Yes, they want to close.
CanIt = true;
}
else
{
// No, they don't want to close.
CanIt = false;
}
return CanIt;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if(CanClose(false) == true)
{
this.Dispose(true);
}
else
{
e.Cancel = true;
}
}
I'm unsure of how to handle the other scenario you mentioned (handling the 'X' click). Maybe you could do something like this (psuedo-code):
// IF CLICKED YES
THEN CLOSE
// ELSE-IF CLICKED NO
THEN DO NOTHING
// ELSE
THEN DO NOTHING