Hi,
In my window application, I want to display a confirm message on form closing. How will I do it? plz, help.
Thanks.
How to display message
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
TulasiRank #2,544 · 549 reputationPosted Oct 6, 2011, 8:57 PM EDT
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
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 6, 2011, 10:23 PM EDT
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