You have to use a recursive function
www.dotnetperls.com/recursion
something along the lines of:
foreach (Control c in MyForm.Controls)
{
UpdateColorControls(c);
}
public void UpdateColorControls(Control myControl)
{
myControl.BackColor = Colors.Black;
myControl.ForeColor = Colors.White;
foreach (Control subC in myControl.Controls)
{
UpdateColorControls(subC);
}
}
Please not that not all controls have a property ForeColor
and BackColor
Update
if you wan't for instance only the textboxes to change:
public void UpdateColorControls(Control myControl)
{
if (myControl is TextBox)
{
myControl.BackColor = Colors.Black;
myControl.ForeColor = Colors.White;
}
if (myControl is DataGridView)
{
DataGridView MyDgv = (DataGridView)myControl;
MyDgv.ColumnHeadersDefaultCellStyle.BackColor = Colors.Black;
MyDgv.ColumnHeadersDefaultCellStyle.ForeColor = Colors.White;
}
// Any other non-standard controls should be implemented here aswell...
foreach (Control subC in myControl.Controls)
{
UpdateColorControls(subC);
}
}