Sometimes you have a program that you would prefer someone not close without confirming they truly meant to close it.
This script will assist in providing a question before the program simply closes.
private void fm1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult dialogResult = MessageBox.Show("Are you sure you want to close?", Application.ProductName, MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { // Truly Close e.Cancel = false; } else if (dialogResult == DialogResult.No) { // Oops Don't close e.Cancel = true; } }
Last Updated on October 26, 2015