C# Color constant R,G,B values

后端 未结 3 1695
Happy的楠姐
Happy的楠姐 2020-12-16 04:58

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

相关标签:
3条回答
  • 2020-12-16 05:25

    It looks like this page has all of them.

    0 讨论(0)
  • 2020-12-16 05:25

    MSDN link

    Colors by name/hex via MSDN

    0 讨论(0)
  • 2020-12-16 05:26

    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);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题