Color类 -- 通过反射将Color中定义的颜色输出

using System.Drawing;
using System.Reflection;

using System.Text;

protected void Page_Load(object sender, EventArgs e)
{
            //以Color 对象为例 输出所有定义的属性颜色
            Type t = typeof(Color);
            PropertyInfo[] properties = t.GetProperties(BindingFlags.Static | BindingFlags.Public);
            StringBuilder sb = new StringBuilder();
            int i = 0;
            foreach (PropertyInfo info in properties)
            {
                sb.AppendFormat("<span style='background-color:{0};width:140px;border:2px solid #336699; margin:5px; line-height:30px; text-align:center; vertical-align:middle'>{0}</span>", info.Name);
                i++;
                //每行显示9个.
                if (i % 9 == 0)
                {
                    sb.Append("<br/>");
                }
            }
            Response.Write(sb.ToString());
}

//输出如图

 

posted @ 2010-01-14 17:32  Tweet  阅读(472)  评论(2编辑  收藏  举报