In my form I have a combobox. It has color names like Red, Yellow, etc.
I want to change backcolor for my form to match the color selected from combobox when I click a button. So far I have this:
private void button_Pass_Click(object sender, EventArgs e)
{
if (comboBox_color.SelectedText == "Red")
{
this.BackColor = System.Drawing.Color.Red;
}
else if (comboBox_color.SelectedText == "Yellow")
{
this.BackColor = System.Drawing.Color.Yellow;
}
else
{
this.BackColor = System.Drawing.Color.Blue;
}
}
When I click the button, the form's BackColor is always set to Blue. What am I doing wrong here?
You can use
Color.FromName