Add an event handler for Form Closing and use this code. This is a really simple solution.
[c language=”#”]
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure?", "Close application", MessageBoxButtons.YesNo) == DialogResult.Yes)
e.Cancel = false;
else
e.Cancel = true;
}
[/c]
Leave a Reply