You put your buttons in an button array
Button[] buttons = new Button[] {button1, button2, .....};
Or in a List<Button>
List<Button> buttons = new List<Button>() { button1, button2, ....);
Next you loop over the button array or the List in the same way
foreach(Button btn in buttons)
btn.BackColor = Color.Black;
Another way to change this property is looping using the Forms.Controls container. But this will work only if the buttons are all contained in the Form.Controls collection.
foreach (Control btn in this.Controls.OfType<Button>())
{
btn.BackColor = Color.Black;
}
To fix the problem of buttons contained in inner ControlCollection you should use a recursive function that loops on every control container and reach buttons eventually inside that container
public void SetBackground(Control.ControlCollection coll)
{
foreach(Control ctr in coll)
{
if(ctr.Controls.Count > 0)
SetBackground(ctr.Controls);
else
{
Button btn = ctr as Button;
if(btn != null) btn.BackColor = Color.Black;
}
}
}
and call it from the toplevel collection
SetBackground(this.Controls);
It is a lot more complicated, so I prefer to use an array to explicitily declare the buttons that need to be changed.