Create an event handler for the FormClosing event
The event argument contains a Cancel Property
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure you want to close the application?",
"Close?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = true;
}
}
Now you only have to develop a new form with three buttons, that returns a
DialogResult.Yes
,
DialogResult.No
and a
DialogResult.Cancel
.
Replace the MessageBox.Show in the above code with code that calls your custom window.