Just wondering whats the big difference between Form.Closed and Form.FormClosed event in the order of events of Windows Application. I've read it in MSDN documentation but still couldn't find anything much different from one another. Please explain.
If the form is a multiple-document interface (MDI) parent form, the FormClosing events of all MDI child forms are raised before the MDI parent form's FormClosing event is raised. Likewise, the FormClosed events of all MDI child forms are raised before the FormClosed event of the MDI parent form is raised.
Then ensure that the event handler is associated with the FormClosing event. The FormClosing event occurs as the form is being closed. When a form is closed, it is disposed, releasing all resources associated with the form. If you cancel this event, the form remains opened.
The FormClosing event occurs as the form is being closed. When a form is closed, it is disposed, releasing all resources associated with the form. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel property of the FormClosingEventArgs passed to your event handler to true.
The FormClosed event occurs after the form has been closed by the user or by the Close method or the Exit method of the Application class. To prevent a form from closing, handle the FormClosing event and set the Cancel property of the CancelEventArgs passed to your event handler to true.
As MSDN says:
The
Closedevent is obsolete in the .NET Framework version 2.0; use theFormClosedevent instead.
I don't think you should even consider using this event. It's deprecated and hidden but it's there only for compatibility with old source code.
It has the same meaning of the FormClosed event but with one (not so much) subtle difference, as you can see on MSDN the Closed event isn't raised when application exists because of a call to Application.Exit() but the FormClosed is.
This behavior is also documented in the link above:
The
Form.ClosedandForm.Closingevents are not raised when theApplication.Exitmethod is called to exit your application. If you have validation code in either of these events that must be executed, you should call theForm.Closemethod for each open form individually before calling theExitmethod.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With