lys*_*cid 4 .net c# controls dispose winforms
我有以下课程:
public class NewListBox : ListBox
{
public NewListBox()
{
}
private ImageList _myImageList;
public ImageList ImageList
{
get { return _myImageList; }
set { _myImageList = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
我感兴趣的是处置这个对象是否会触发对象上的字段的处理,比如ImageList,或者我应该实现(覆盖)Dispose方法并自己完成这项工作?
您应该将ImageList添加到控件的Components集合中,然后Dispose的基类实现将Dispose在该集合中的所有内容,您不必重置Dispose.
如果您有任何IDisposable成员但不是Components,那么您必须在控件中覆盖Dispose并自行处理它们.
(我严格意义上使用从System.ComponentModel.Component派生的对象中的Component一词).
归档时间: |
|
查看次数: |
7001 次 |
最近记录: |