Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a color in string type variable but i dont know how can i convert this string to color and then set this color to button background .
please help me how can i do this
i have try this. But fail
error message is display
cat.BackColor =Color.mycolor;

under
mycolor

error message is
Color does not contain a definition for mycolor


What I have tried:

String backcolor="Red";
Color mycolor = ColorTranslator.FromHtml(backcolor);
            cat.BackColor =Color.mycolor;

cat is a button Name.
Posted
Updated 26-Jan-19 12:12pm

1 solution

Did you try :
C#
String backcolor="Red";
Color mycolor = ColorTranslator.FromHtml(backcolor);
cat.BackColor =mycolor;

or
C#
String backcolor="Red";
cat.BackColor = ColorTranslator.FromHtml(backcolor);

?
 
Share this answer
 
Comments
Fahid Zahoor 26-Jan-19 18:52pm    
2nd method is work now. Thanks
Maciej Los 6-Feb-19 6:27am    
5ed!
Patrice T 6-Feb-19 6:28am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900