Handling the Close Event

i'm using C# with the original vs .net, and i don't want the form to close when the user clicks the X in the top right corner.

instead i want to handle the event and ask the user to save before closing,
i know how to add a method as an event handler for the close event, but i don't know how to stop the form from closing

is there any way to dissable the default handler for the close event


Answer this question

Handling the Close Event

  • sign

    Hello,

    Just to clarify what DanielRieck answered.

    Closing event when the user close the form by any way, u can use this event to tell the user saving or not. Use the cancel property of the (e) setting it to True will not continue exiting.

    The close event will fire just after the form is closed.

    Hope that help and clear

  • Amol Wankhede

    Use the Closing event instead. If the user doesn't want to close the program, set the Cancel property on the CancelEventArgs to true.
  • zqzproject

    Thanks a lot dan, it works perfectly.
  • Handling the Close Event