Search code examples
.netwinformsidisposablegenerated-code

IDisposable Winform


What is the best practice for implementing IDisposable on a Winform?

  • I have a dialog which extends System.Windows.Forms.Form
  • The generated designer.cs already contains an implementation of the virtual Dispose(bool) method
  • My form has a field added manually which implements IDisposable

Ideally I would be able to hook into the Dispos(bool) override in the generated code to dispose the manually added IDisposable object. Any recommendations on how to do this properly?

Thanks.

Scott


Solution

  • You can move that Dispose implementation out of the .designer.cs and in your .cs.