If you are talking about WinForms, I usually take one of two approaches to solve this problem.
Approach 1
Open the Form.Designer.cs file. Inside the generated placement method, I add a call to DisposeCore. Then I go back to Form.cs and add the DisposeCore method, which will now be called during deletion. I add all my logic to this method.
Editing the constructor file is not technically supported. However, I found that this particular editing will not be washed away when the designer regenerates the code.
Approach 2
Add an event handler to Form.Disposed and execute your delete logic in the handler. This is the preferred method because it is a supported operation and will not be affected by any creation of a designer that you have yet to face.
JaredPar Mar 23 '09 at 13:08 2009-03-23 ββ13:08
source share