Posted 18 years ago
by Logicway
I am using events on OnCancelButtonClick and OnFormClosing.
It seems that OnCancelButtonClick-events fires also the OnFormClosing-event.
When the user clicks the cancelbutton and clicks OK on the dialog, this fires again a dialog.
How can I prevent this?
It seems that OnCancelButtonClick-events fires also the OnFormClosing-event.
protected override void OnCancelButtonClick(EventArgs e)
{
DialogResult cancel = new DialogResult();
cancel = MessageBox.Show("Are you sure?", "?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (cancel == DialogResult.OK)
{
this.Close();
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
DialogResult close = new DialogResult();
close = MessageBox.Show("Do you want to exit?", "?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (close == DialogResult.OK)
{
e.Cancel = false;
}
else if (close == DialogResult.Cancel)
{
e.Cancel = true;
}
}
How can I prevent this?