7

在哪里可以找到所有 C# 颜色常量和相关 R、G、B(红、绿、蓝)值的列表?

例如

颜色.白色 == (255,255,255)

颜色.黑色 == (0,0,0)

ETC...

4

3 回答 3

24

运行这个程序:

using System;
using System.Drawing;
using System.Reflection;

public class Test
{
    static void Main()
    {
        var props = typeof(Color).GetProperties(BindingFlags.Public | BindingFlags.Static);
        foreach (PropertyInfo prop in props)
        {
            Color color = (Color) prop.GetValue(null, null);
            Console.WriteLine("Color.{0} = ({1}, {2}, {3})", prop.Name,
                              color.R, color.G, color.B);
        }
    }
}

或者:

using System;
using System.Drawing;

public class Test
{
    static void Main()
    {
        foreach (KnownColor known in Enum.GetValues(typeof(KnownColor)))
        {
            Color color = Color.FromKnownColor(known);
            Console.WriteLine("Color.{0} = ({1}, {2}, {3})", known,
                              color.R, color.G, color.B);
        }
    }
}
于 2008-10-22T14:26:55.420 回答
9

看起来此页面包含所有这些。

于 2008-10-22T14:26:19.133 回答
5

MSDN 链接

通过 MSDN 按名称/十六进制着色

于 2008-10-22T18:52:12.250 回答