The documentation states: "Use the
Controls property to iterate through all controls of a form, including nested controls."
This doesn't seem to be quite right unless "nested" means something different than child controls. The following code does not iterate over child controls:
foreach(Control ctrl in parentControl.Controls) {
...
}
In order to access all of the controls, including nested/child controls, use this code:
public void Foo(Control.ControlCollection controls) {
foreach(Control ctrl in controls) {
...
Foo(ctrl.Controls);
}
}
Admittedly, this is recursive code. Generally speaking this should be avoided in order to avoid stack overruns. However, in this particular case it is probably acceptable since the number of levels in any form should be fairly limited.