News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

How can I display a pop up a confirmation dialog when the user closes the form?

Started by nandagopal, Jul 05, 2008, 08:36 PM

Previous topic - Next topic

nandagopal

You can listen to the Form's Closing event, where you can display a MessageBox as show below:
[C#]
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
     if (MessageBox.Show("Do you want to close the application?", "Close Application", MessageBoxButtons.YesNo) == DialogResult.No)
          e.Cancel = true;

}
[VB.NET]
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
     If MessageBox.Show("Do you want to close the application?","Close Application",MessageBoxButtons.YesNo) = DialogResult.No Then
          e.Cancel = True
     End If

End Sub