Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Dispose in designed form or user control

Tags:

c#

winforms

I've created a custom WinForms UserControl and would like to override Dispose. However the code generated by the designed already contains a Dispose method. How can I add custom cleanup code to my component?

like image 673
Randy Voet Avatar asked Apr 06 '11 13:04

Randy Voet


2 Answers

You can move the Dispose method from the code generated file into your control cs file. I've used this under .net 2.0, it should work on 4.0 as well.

like image 196
Stefan P. Avatar answered Oct 04 '22 17:10

Stefan P.


It's badly documented but you can Cut & Paste the Dispose method over to your side of the partial class.
And then extend it.

like image 32
Henk Holterman Avatar answered Oct 04 '22 17:10

Henk Holterman