zoukankan      html  css  js  c++  java
  • [C#]生成预定义全颜色表

    生成Color类所有static预定义成员的颜色表

                const long CELLS_PER_LINE = 10;
    
                const float MARGIN = 12;
                const float CELL_WIDTH = 160;
                const float CELL_HEIGHT = 64;
                const float COLOR_LEFT_MARGIN = 8;
                const float COLOR_TOP_MARGIN = 8;
                const float COLOR_CELL_WIDTH = 48;
                const float COLOR_CELL_HEIGHT = 32;
                const float TEXT_TOP_MARGIN = COLOR_TOP_MARGIN + COLOR_CELL_HEIGHT + 2;
    
                List<Color> vColors = new List<Color>();
                Type t = typeof(Color);
                PropertyInfo[] vProps = t.GetProperties();
                foreach (PropertyInfo propInfo in vProps)
                {
                    if (MemberTypes.Property == propInfo.MemberType &&
                        typeof(Color) == propInfo.PropertyType)
                    {
                        Color tmpColor = (Color)propInfo.GetValue(null, null);
                        vColors.Add(tmpColor);
                    }
                }
    
                Bitmap bmpColor = new Bitmap((int)(CELLS_PER_LINE * CELL_WIDTH + MARGIN * 2), (int)((vColors.Count / CELLS_PER_LINE + 1) * CELL_HEIGHT + MARGIN * 2));
                using (Graphics grp = Graphics.FromImage(bmpColor))
                {
                    grp.Clear(Color.Black);
    
                    for (int i = 0; i < vColors.Count; i++)
                    {
                        float nLeftBase = MARGIN + i % CELLS_PER_LINE * CELL_WIDTH;
                        float nTopBase = MARGIN + i / CELLS_PER_LINE * CELL_HEIGHT;
    
                        grp.DrawRectangle(new Pen(Color.White), nLeftBase, nTopBase, CELL_WIDTH, CELL_HEIGHT);
    
                        grp.FillRectangle(new SolidBrush(vColors[i]),
                                          nLeftBase + COLOR_LEFT_MARGIN, nTopBase + COLOR_TOP_MARGIN,
                                          COLOR_CELL_WIDTH, COLOR_CELL_HEIGHT);
    
                        grp.DrawString(vColors[i].Name,
                                       new Font("宋体", 9, FontStyle.Regular),
                                       new SolidBrush(Color.White),
                                       nLeftBase + COLOR_LEFT_MARGIN, nTopBase + TEXT_TOP_MARGIN);
                    }
                }
    
                bmpColor.Save(@"D:AllColor.bmp");


    生成效果如图:

  • 相关阅读:
    最大连续序列和
    打印有序链表的公共部分
    字符串最长子串大小
    jvm简介
    大浮点数乘法
    java代码的快速排序理解
    从内存分配分析程序初始化和存储
    时间复杂度
    Filter&Listener
    MVC开发模式&EL表达式&JSTL&三层架构开发
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3362215.html
Copyright © 2011-2022 走看看