C# 颜色常量 R、G、B 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/225953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 18:55:56 来源:igfitidea点击:
C# Color constant R,G,B values
提问by TK.
Where can I find a list of all the C# Color constants and the associated R,G,B (Red, Green, Blue) values?
在哪里可以找到所有 C# 颜色常量和相关 R、G、B(红色、绿色、蓝色)值的列表?
e.g.
例如
Color.White == (255,255,255)
Color.White == (255,255,255)
Color.Black == (0,0,0)
颜色.黑色 == (0,0,0)
etc...
等等...
采纳答案by Jon Skeet
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);
}
}
}