在处理用户控件​​,真正的意思修改了.Designer.cs文件? [英] Dispose on user controls, really meant to edit the .designer.cs file?

查看:439
本文介绍了在处理用户控件​​,真正的意思修改了.Designer.cs文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于必须处理内部数据结构的用户控件,是正确的地方,该代码添加到该文件了.Designer.cs Dispose方法,还是有我们的意思,而不是使用事件或某事?

For a user control with internal data structures that must be disposed, is the correct place to add that code to the Dispose method in the .designer.cs file, or is there an event or something we're meant to use instead?

修改:这是一个WinForms用户控件

Edit: This is a winforms user control.

推荐答案

如果你在谈论的WinForms我通常采取两种方法之一来解决这个问题。

If you're talking about WinForms I usually take one of two approaches to solve this problem.

方法1

打开Form.Designer.cs文件。内部生成的Dispose方法我添加到DisposeCore通话。然后我回去Form.cs并添加DisposeCore方法,将现在处置过程中被调用。我想补充我所有的处置逻辑此方法。

Open the Form.Designer.cs file. Inside the generated dispose method I add a call to DisposeCore. I then go back to Form.cs and add a DisposeCore method that will now be called during dispose. I add all of my dispose logic into this method.

编辑设计器文件在技术上不支持。但是我发现,当设计师重新生成代码,这个特殊的编辑不会被冲走。

Editing the designer file is technically not supported. However I've found that this particular edit will not be washed away when the designer regenerates code.

方法2

添加事件处理程序Form.Disposed,做我处置逻辑处理器。这是最好的方式,因为它是一个支持的操作,不会被一些设计师代你还没有遇到受到影响。

Add a event handler to Form.Disposed and do my dispose logic in the handler. This is the preferable way because it's a supported operation and won't be affected by some designer generation you have yet to encounter.

这篇关于在处理用户控件​​,真正的意思修改了.Designer.cs文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆