Custom Dispose in designed form or user control

前端 未结 4 1616
说谎
说谎 2021-01-05 13:22

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 c

相关标签:
4条回答
  • 2021-01-05 13:38

    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.

    0 讨论(0)
  • 2021-01-05 13:40

    Depending on what kind of resources you want to dispose of you also could use finalizer (destructor) to achieve that as well.

    0 讨论(0)
  • 2021-01-05 13:44

    I just realized that the Dispose method in the x.Designer.cs is outside the 'Component Designer generated code' region. So simply moving the Dispose method to my normal 'code behind' solves my problem.

    0 讨论(0)
  • 2021-01-05 13:50

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

    0 讨论(0)
提交回复
热议问题