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;
        }
    }
  • 相关阅读:
    将当前日期转换成年-月- 日格式
    js修改title
    Window.open()方法参数详解总结(转)
    js(jQuery)获取时间的方法及常用时间类
    用express搭建一个简单的博客系统
    字符串、数组相互转换 对象转换为数组的方法
    多文件上传 input 的multiple 属性
    关于iframe的使用 以及自适应页面高度
    浏览器转换为兼容模式
    分类算法之随机森林
  • 原文地址:https://www.cnblogs.com/SkySoot/p/2342978.html
Copyright © 2011-2022 走看看