Hi,
In my window application, I want to display a confirm message on form closing. How will I do it? plz, help.
Thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Prabhu RajaPosted Oct 7, 2011, 2:23 AM
The Code Given by Vidya is Excellent. Also I want suggest Two Things.
1) you may use MessageBoxButtons.YesNo instead Of MessageBoxButtons.OKCancel, It will Looks like a real Confirmation Box i think.
2) Use Else Block Also, That may Increase Your Code readability. Likr
if (MessageBox.Show("Do u want to close", "Confirmation Box", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
e.Cancel = true;
else
e.Cancel = false
------------------------------------------
Thank You
TulasiPosted Oct 7, 2011, 12:57 AM
Check the following code
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Do u want to close", "Confirmation Box", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
e.Cancel = true;
}
-----------------------------------------------------------------------
If this helps you, then mark as "Correct Answer"
Thank You