Link to home
Start Free TrialLog in
Avatar of programmer_bmb
programmer_bmb

asked on

Casting From String To Color in C#

Hi to alll ...
I want to save color in regeistry as a text, But how could I convert it to Color object after retreiving the value from regustry ....
the following code doesn't work
Text.BackColor = ((Color)GetValue(....path.....))

thanks


Avatar of Jarodtweiss
Jarodtweiss

Color is an enumeration and so you can get the corresponding color from the name using that syntax :

String s = "Blue"
Color c = (Color)Enum.Parse(typeof(Color), s);
You may include that in a try catch block as an ArgumentException can be thrown if the provided string is not a correct Color
ASKER CERTIFIED SOLUTION
Avatar of eternal_21
eternal_21

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial