zoukankan      html  css  js  c++  java
  • Brush 色谱

    运行效果如下:

    image

    程序源代码如下:

    using System;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Reflection;
    using System.Collections.Generic;
     
    namespace ShowColor
    {
        /// <summary>
        /// 显示标准颜色
        /// </summary>
        public class ShowColor : Form
        {
            public static void Main(string[] args)
            {
                Application.Run(new ShowColor());
            }
     
            /// <summary>
            /// 初始化窗体设置
            /// </summary>
            public ShowColor()
            {
                this.Text = "ShowColor";
                this.ClientSize = new Size(800, 630);
                this.Paint += new PaintEventHandler(this.PaintForm);
                this.SizeChanged += new EventHandler(this.RefreshForm);
            }
     
            /// <summary>
            /// 窗体尺寸改变,重绘窗体
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void RefreshForm(object sender, EventArgs e)
            {
                this.Invalidate();
            }
     
            /// <summary>
            /// 重绘窗体
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void PaintForm(object sender, PaintEventArgs e)
            {
                // 获取 Brushes 所有公有属性
                PropertyInfo[] props = typeof(Brushes).GetProperties();
     
                // 创建 brushes 集合
                List<BrushWithName> brushes = new List<BrushWithName>();
                foreach (var prop in props)
                {
                    BrushWithName entity = new BrushWithName();
                    entity.Name = prop.Name;
                    entity.Value = (Brush)prop.GetValue(null, null);
                    brushes.Add(entity);
                }
     
                // 画出这个色彩图
                Size clientSize = this.Size;
                // 矩形条尺寸
                Size blockSize = new Size(clientSize.Width / 4, clientSize.Height / (brushes.Count / 4));
                // 绘画起始点
                Point location = new Point();
                // 列数
                int cols = 0;
     
                foreach (BrushWithName entity in brushes)
                {
                    Graphics g = e.Graphics;
                    g.FillRectangle(entity.Value, new Rectangle(location, blockSize));
                    g.DrawString(entity.Name, new Font("宋体", 10), Brushes.Black, location);
                    location.Offset(blockSize.Width, 0);// X 坐标横移
                    cols++;
                    if (cols == 4)
                    {
                        location = new Point(0, location.Y + blockSize.Height);// X 归零,Y 横移
                        cols = 0;
                    }
                }
            }
        }
     
        /// <summary>
        /// 色谱实体类
        /// </summary>
        class BrushWithName
        {
            public Brush Value;
            public String Name;
        }
    }
  • 相关阅读:
    大数据量并发处理
    一网打尽当下NoSQL类型、适用场景及使用公司
    高并发,大数据量,你的系统考虑哪些问题?
    在学习的路上
    CheckBox全选JS代码
    关于时间的两个写法
    Asp.Net MVC4.0 官方教程拓展之一为模型属性增加中文显示名称
    Asp.Net MVC4.0 官方教程 入门指南之八为Movie模型和库表添加字段
    Asp.Net MVC4.0 官方教程 入门指南之六查看Edit方法和Edit视图
    Asp.Net MVC4.0 官方教程 入门指南之五控制器访问模型数据
  • 原文地址:https://www.cnblogs.com/SkySoot/p/2342978.html
Copyright © 2011-2022 走看看