What would be the event to catch when a UserControl
is disposed of in C# ? I'd like to catch it to do some clean up, but after viewing the list of events available in the designer, it seems there is no such thing ?
When you create the user control a Dispose method is created automatically for you in the yourUserControlName.Designer.cs file. Add whatever clean up code that method. You may want to change the auto generated code to something like this:
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
// your clean up code here
}
base.Dispose(disposing);
}
That way your clean up code will not be dependent on the components object.
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