开发者

c#, Controls in panel to be disposed

Okay, here a situation:

1) I have a Panel called "panel1" that consist one UserControl.

2) If I coded with this line "panel1.dispose();". Will UserControl inside this pan开发者_如何转开发el1 dispose as well?


Yes.
Disposing a WinForms control will also dispose all of its child controls.

You can see this in the source:

ControlCollection controlsCollection = (ControlCollection)Properties.GetObject(PropControlsCollection); 

if (controlsCollection != null) { 

    // PERFNOTE: This is more efficient than using Foreach.  Foreach
    // forces the creation of an array subset enum each time we 
    // enumerate
    for(int i = 0; i < controlsCollection.Count; i++) {
        Control ctl = controlsCollection[i];
        ctl.parent = null; 
        ctl.Dispose();
    } 
    Properties.SetObject(PropControlsCollection, null); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜