.NET - Converting Color Name Strings into System.Drawing.Color

32.9k Views Asked by At

What is the best way to turn strings like "red", "green", "yellow", "aliceblue", etc... into the actual System.Drawing.Color value?

I was looking at reflection and something about that didn't seem right.

3

There are 3 best solutions below

0
On BEST ANSWER

You can use Color.FromName()

2
On

System.Drawing.Color.FromName("Red");

0
On

System.Drawing.Color has a static method:

public static Color FromName(string name)

Use it like so:

   Color c = Color.FromName("AliceBlue")