sounds like you should be using radio buttons not checkboxes.
Radio buttons are mutually exclusive.
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
if (this.radioButton1.Checked)
{
this.radioButton1.BackColor = System.Drawing.Color.Green;
}
else
{
this.radioButton1.BackColor = System.Drawing.Color.Transparent;
}
if (this.radioButton2.Checked)
{
this.radioButton2.BackColor = System.Drawing.Color.Red;
}
else
{
this.radioButton2.BackColor = System.Drawing.Color.Transparent;
}
}
if you insist on using checkboxes you will need to know which one was clicked and will need to uncheck it first keeping this in the click event.
maybe best to have separate click events for each radio button to uncheck the other
private void cbCorrect_Click(object sender, EventArgs e)
{
if (this.cbCorrect.Checked)
{
this.cbCorrect.BackColor = System.Drawing.Color.Green;
this.cbWrong.Checked = false;
this.cbWrong.BackColor = System.Drawing.Color.Transparent;
}
else
{
cbCorrect.BackColor = System.Drawing.Color.Transparent;
}
}
private void cbWrong_Click(object sender, EventArgs e)
{
if (this.cbWrong.Checked)
{
this.cbWrong.BackColor = System.Drawing.Color.Red;
this.cbCorrect.Checked = false;
this.cbCorrect.BackColor = System.Drawing.Color.Transparent;
}
else
{
cbWrong.BackColor = System.Drawing.Color.Transparent;
}
}