C# Color constant R,G,B values

强颜欢笑 提交于 2019-12-18 03:39:40

问题


Where can I find a list of all the C# Color constants and the associated R,G,B (Red, Green, Blue) values?

e.g.

Color.White == (255,255,255)

Color.Black == (0,0,0)

etc...


回答1:


Run this program:

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);
        }
    }
}

Or alternatively:

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);
        }
    }
}



回答2:


It looks like this page has all of them.




回答3:


MSDN link

Colors by name/hex via MSDN



来源:https://stackoverflow.com/questions/225953/c-sharp-color-constant-r-g-b-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!