How to set color management without using enumeration?

I want to set the color of my control using a string variable with a value of "blue". Usually you should install it:

Label1.Color = Color.Blue;

But now I want to replace Color.Blue with a value that is in my string variable, for example:

Label1.Color = sColor; // sColor = "Blue"

But I get an error: Cannot convert type 'string' to "System.Drawing.Color"

Any help was appreciated.

+3
source share
2 answers

Use the Color.FromName function to pass in a string:

Color slateBlue = Color.FromName("SlateBlue");
+4
source

, , , , case.

:

System.Drawing.Color colorValue = (System.Drawing.Color)Enum.Parse(typeof(System.Drawing.Color), sColor);
0

Source: https://habr.com/ru/post/1759520/