Recycle on custom controls really designed to edit the .designer.cs file?

For a user control with internal data structures to be located, this is the right place to add this code to the Dispose method in the .designer.cs file or is there some kind of event or something that we should use instead

Change This is a custom winforms element.

+3
c # idisposable controls dispose user
Mar 23 '09 at 11:12
source share
3 answers

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.

+3
Mar 23 '09 at 13:08
source share

Could you clarify what means of control? ASP.NET, WinForms?

In ASP.NET you can:

protected override void OnUnload(EventArgs e){ base.OnUnload(e); //Unload here... } 
+1
Mar 23 '09 at 11:22
source share

Or you can cut and paste it into the main .cs file. This code is not inside the "generated #region constructor constructor code", so Studio will not skip it.

+1
Feb 26 '14 at 2:37
source share



All Articles