取System.Drawing.Color定义的颜色

来源:互联网 发布:c盘windows文件夹太大 编辑:程序博客网 时间:2024/05/21 18:50

     /// <summary>
        /// 取System.Drawing.Color定义的颜色
        /// </summary>
        /// <param name="index">index</param>
        /// <returns>string</returns>
        public static string GetColorList(int index)
        {           
            Type colorType = typeof(Color);
            PropertyInfo[] info = colorType.GetProperties();
            List<string> colorList = new List<string>();

            for (int i = 0; i < info.Length; i++)
            {
                if (info[i].PropertyType.ToString() == "System.Drawing.Color")
                {
                    if(info[i].Name != "Transparent")
                        colorList.Add(info[i].Name);
                }
            }


            if (index >= colorList.Count)
            {
                index = index % colorList.Count;               
            }

            return colorList[index];
        }

原创粉丝点击