In this case, I'd want to invest a little more time and effort to get something that can be re-used. And, I'd want something that could operate on any particular kind of control, and that could be run with and without recursive checking for controls within controls:
private void SetControlsEnabledProperty(bool isEnabled, bool isRecursive, string typeToCheck, Control.ControlCollection theControls)
{
foreach (Control theControl in theControls)
{
if (theControl.GetType().Name == typeToCheck)
{
theControl.Enabled = isEnabled;
}
else
{
if (isRecursive && theControl.HasChildren)
{
SetControlsEnabledProperty(isEnabled, isRecursive, typeToCheck, theControl.Controls);
}
}
}
}
}
I might call this function like this to iterate all the Controls in a Form, and set every TextBox's Enabled property to true:
SetControlsEnabledProperty(true, true, "TextBox", this.Controls);