.NET - Converting Color Name Strings into System.D

2019-03-25 02:46发布

问题:

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.

回答1:

You can use Color.FromName()



回答2:

System.Drawing.Color has a static method:

public static Color FromName(string name)

Use it like so:

   Color c = Color.FromName("AliceBlue")


回答3:

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