【问题标题】:C# Color constant R,G,B valuesC# 颜色常数 R,G,B 值
【发布时间】:2008-10-22 14:22:48
【问题描述】:

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

例如

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

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

等等……

【问题讨论】:

    标签: c# colors rgb system.drawing.color


    【解决方案1】:

    运行这个程序:

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

    【讨论】:

    • 我更喜欢使用第一个,因为使用 KnownColor 会添加系统中控件和窗口的颜色。
    【解决方案2】:

    看起来page 拥有所有这些。

    【讨论】:

      【解决方案3】:
      猜你喜欢
      • 2017-12-30
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      相关资源
      最近更新 更多