foreach (Control ctrl in this.Controls) {
If you need access to all controls in the form and all the controls for each in the form of control (and so on, recursively), use the following function:
public void DoSomething(Control.ControlCollection controls) { foreach (Control ctrl in controls) {
... that you are calling, first passing a Controls collection, for example:
DoSomething(this.Controls);
source share