.NET - Converting Color Name Strings into System.D

2019-03-25 02:10发布

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条回答
唯我独甜
2楼-- · 2019-03-25 02:52

You can use Color.FromName()

查看更多
手持菜刀,她持情操
3楼-- · 2019-03-25 03:01

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

查看更多
何必那么认真
4楼-- · 2019-03-25 03:02

System.Drawing.Color has a static method:

public static Color FromName(string name)

Use it like so:

   Color c = Color.FromName("AliceBlue")
查看更多
登录 后发表回答