从System.Drawing.Color获取所有的命名的标准颜色对应的RGB值

System.Drawing.Color类中定义了一系列的命名颜色和一系列的有关颜色的方法。我们如何从这个类中提取它们呢?并且想知道他们这命名的颜色对应的RGB是多少呢?

 public static IList<Color> GetAllColors()
        {
            Type type = typeof(Color);
            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Static);
            return props.Select(s => s.GetValue(null)).Select(s => (Color)s).ToList();
        }

这样你就可以循环遍历输出它们的R、G、B值了。

如果你想更详细查看这141种颜色的hex值的话,不妨到 http://www.yansedaquan.com/SeBan/Color 

效果图如下:

颜色

猜你喜欢

转载自blog.csdn.net/ahua001/article/details/81168427