C# Color constant R,G,B values

21,358

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

Solution 2

It looks like this page has all of them.

Solution 3

MSDN link

Colors by name/hex via MSDN

Share:
21,358
TK.
Author by

TK.

--

Updated on April 18, 2020

Comments

  • TK.
    TK. about 4 years

    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...

  • hila shmueli
    hila shmueli almost 14 years
    i'd prefer to use the first one because using KnownColor adds the color of the controls and windows in the system.