If you want to change color with clicks on buttons then
connect these event handlers to each button's Clicked event.
private void btnRed_Clicked(object sender, EventArgs e)
{
panel.BackColor = Colors.Red;
}
private void btnGreen_Clicked(object sender, EventArgs e)
{
panel.BackColor = Colors.Green;
}
private void btnBlue_Clicked(object sender, EventArgs e)
{
panel.BackColor = Colors.Blue;
}
In order to change color with combination of buttons I suggest to replace buttons with checkBoxes and add this event handler to each checkBox's Checked event.
void checkBox_Checked(object sender, EventArgs e)
{
int state = 0;
if(btnRed.Checked)
{
state += 1;
}
if(btnGreen.Checked)
{
state += 2;
}
if(btnBlue.Checked)
{
state += 4;
}
switch(state)
{
case 1:
panel.BackColor = Colors.Red;
break;
case 2:
panel.BackColor = Colors.Green;
break;
case 4:
panel.BackColor = Colors.Red;
break;
case 3:
break;
default:
panel.BackColor = SystemColors.Control;
}
}