In the thread .NET / Windows Forms: remember windows size and location, multiple solutions for saving the size and location of the form are given. However, all of them suggests saving the information in the FormClosing
event handler. I'm curious: is there any problem with saving the information in FormClosed
? It seems more natural to me, because that is the event where we are certain the form is being closed. When I tested, both events seem to work fine.
It seems more natural to me, because that is the event where we are certain the form is being closed.
FormClosing
occurs just before FormClosed
event. Unless you cancel it in the FormClosing
event, you can still be certain that it is going to be closed.
You can use this event to perform tasks such as freeing resources used by the form and to save information entered in the form or to update its parent form.
However, note that whenever you close your program's startup form, the entire application should exit automatically.
As you have noticed, it will work for most of the time. But you might experience some weird behaviors (not saving settings) time to time.
When it comes to saving the size and location, there are more tricky things to consider, especially when you have multiple monitors with different resolutions/size and etc. So, I would eliminate one possible risk. So, unless there is any good reason to use FormClosed
, I would use FormClosing
for this purpose.