我怎样才能得到的System.Drawing.Color所有颜色的集合? [英] How can I get a collection of all the colors in System.Drawing.Color?

查看:198
本文介绍了我怎样才能得到的System.Drawing.Color所有颜色的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何提取的颜色的的System.Drawing.Color结构列表到一个集合或数组?

How can I extract the list of colors in the System.Drawing.Color struct into a collection or array?

有没有得到的颜色的集合比使用这种结构为基础的更有效的方法?

Is there a more efficient way of getting a collection of colors than using this struct as a base?

推荐答案

所以,你会怎么做:

string[] colors = Enum.GetNames(typeof(System.Drawing.KnownColor));

......让所有的collors的数组。

... to get an array of all the collors.

或者......你可以使用反射来刚才得到的颜色。 KnownColors包括像菜单,系统菜单的颜色,等这个项目可能不是你想要的是什么。因此,要得到的System.Drawing.Color颜色的只是名字,你可以使用反射:

Or... You could use reflection to just get the colors. KnownColors includes items like "Menu", the color of the system menus, etc. this might not be what you desired. So, to get just the names of the colors in System.Drawing.Color, you could use reflection:

Type colorType = typeof(System.Drawing.Color);

PropertyInfo[] propInfoList = colorType.GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);

foreach (System.Reflection.PropertyInfo c in propInfoList) {
  Console.WriteLine(c.Name);
}

本写出所有的颜色,但你可以很容易地调整它的颜色名称添加到列表中。

This writes out all the colors, but you could easily tailor it to add the color names to a list.

看看这个code项目上项目建设彩色图表

Check out this Code Project project on building a color chart.

这篇关于我怎样才能得到的System.Drawing.Color所有颜色的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆