C#正从颜色所有颜色 [英] C# getting all colors from Color
本文介绍了C#正从颜色所有颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打一个组合框
装满了来自的System.Drawing.Color
I want to make a ComboBox
filled with all the colors from System.Drawing.Color
但我似乎无法从该集合收集所有的颜色
But I can't seem to collect all the colors from that collection
我使用已经尝试了的foreach
做这样的工作:
I've already tried using a foreach
to do the job like this:
foreach (Color clr in Color)
{
}
但我得到的是一个错误。
But all I get is an error.
所以,我怎么能循环低谷所有的颜色?
So how can I loop trough all the colors?
任何帮助将AP preciated。
Any help will be appreciated.
推荐答案
您可以采取颜色从的 KnownColor
KnownColor[] colors = Enum.GetValues(typeof(KnownColor));
foreach(KnownColor knowColor in colors)
{
Color color = Color.FromKnownColor(knowColor);
}
或使用反射来避免类似颜色的菜单的桌面... 的包含KnowColor
or use reflection to avoid color like Menu, Desktop... contain in KnowColor
Type colorType = typeof(System.Drawing.Color);
// We take only static property to avoid properties like Name, IsSystemColor ...
PropertyInfo[] propInfos = colorType.GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);
foreach (PropertyInfo propInfo in propInfos)
{
Console.WriteLine(propInfo.Name);
}
这篇关于C#正从颜色所有颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文