Confirmation Message Before closing windows form using C#

Post date: Mar 17, 2011 12:26:22 PM

A FormClosing event is raised for every form represented by the OpenForms property. This event can be canceled by setting the Cancel property of their FormClosingEventArgs parameter to true. If one of more of the handlers cancels the event, then Exit returns without further action. Otherwise, a FormClosed event is raised for every open form, then all running message loops and forms are closed.

private void frmConnectServer_FormClosing(object sender, FormClosingEventArgs e)

{            if (DialogResult.Yes == MessageBox.Show("Are you want continue without install Databae? ", IConstants.MSG_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2))

            { return;  }

            else

            { e.Cancel = true; }

           

        }