You can put the 20 buttons in a list.
On click: iterate the list and change the colour.
public class TheForm : Form
{
private List<Button> _theList = new List<Button>();
public TheForm()
{
InitializeComponent();
PopulateList();
}
private void PopulateList()
{
_theList.AddRange(new Button[] {
button01, button02, button03, button04, button05,
button06, button07, button08, button09, button10,
button11, button12, button13, button14, button15,
button16, button17, button18, button19, button20
});
}
private void TheButton_Click(object sender, EventArgs e)
{
foreach (Button button in _theList)
{
button.BackColor = ;
}
}
}
button01
to
button20
are the
Name
s of button instances on your form.