private void SetRedColorToTextBoxes()
{
Action<Control.ControlCollection> func = null;
func = (controls) =>
{
foreach (Control control in controls)
if (control is TextBox)
(control as TextBox).BackColor = Color.Red;
else
func(control.Controls);
};
func(Controls);
}
and call SetRedColorToTextBoxes()
function in form load.
private void YourForm_Load(object sender, EventArgs e)
{
SetRedColorToTextBoxes();
}
Edit
Add a .cs file and put the code there.
class Helper
{
public void SetRedColorToTextBoxes(Form frm)
{
Action<Control.ControlCollection> func = null;
func = (controls) =>
{
foreach (Control control in controls)
if (control is TextBox)
(control as TextBox).BackColor = Color.Red;
else
func(control.Controls);
};
func(frm.Controls);
}
}
and call it your form load as :
private void YourForm_Load(object sender, EventArgs e)
{
// this means instance of currentform.
(new Helper()).SetRedColorToTextBoxes(this);
}