If you only want to clear TextBox
es you can do it easily like this:
foreach(TextBox tb in this.Controls.OfType<TextBox>())
tb.Text = string.Empty;
But that will only clear all the TextBox
es that are directly on the Form
and not inside a GroupBox
or Panel
or any other container.
If you have TextBox
es inside other containers you need to recurse:
private void ClearTextBoxes(ControlCollection controls)
{
foreach(TextBox tb in controls.OfType<TextBox>())
tb.Text = string.Empty;
foreach(Control c in controls)
ClearTextBoxes(c.Controls);
}
Call this like ClearTextBoxes(this.Controls);