c# - Change backcolor according to color selected from combobox -
in form have combobox. has color names red, yellow, etc.
i want change backcolor form match color selected combobox when click button. far 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 click button, form's backcolor set blue. doing wrong here?
you can use color.fromname
this.backcolor = color.fromname(combobox_color.selecteditem.tostring()); if name parameter not valid name of predefined color, fromname method creates color structure has argb value of 0 (that is, argb components 0).
Comments
Post a Comment