开发者

c#, Controls in panel to be disposed

开发者 https://www.devze.com 2023-03-24 18:04 出处:网络
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 dispo

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

精彩评论

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