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);
}
精彩评论