What is the difference between the Form_Close() and Form_Closing() events? If I want to empty variables (ie: Var = 0) which event would be better?
Printable View
What is the difference between the Form_Close() and Form_Closing() events? If I want to empty variables (ie: Var = 0) which event would be better?
Form_Closing() is where you should put the code to validate if yes or no the form will be close. by setting the e parameter
it append just before de form is close.VB Code:
e.Cancel=True
In the Form_Close()
The form is close so this is the place you should reset value or else ...
:afrog:
Form_Close is an instruction, a method indicating the form should be closed now.
Form_Closing is a happening, an event which is executed AS the form is closing.
Theoretically I guess both should be valid in disposing objects, but out of habit I usually use the Close() method.
MSDN seems to have a similar description for both:
Quote:
When a form is closed, all resources created within the object are closed and the form is disposed. You can prevent the closing of a form at run time by handling the Closing event and setting the Cancel property of the CancelEventArgs passed as a parameter to your event-handling method. If the form you are closing is the startup form of your application, your application ends.
The Closing event occurs as the form is being closed. When a form is closed, all resources created within the object are released and the form is disposed. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel property of the CancelEventArgs passed to your event handler to true.
OK, thats great, just what the doctor ordered :D Thanks for the quick reply guys!