zoukankan      html  css  js  c++  java
  • WPF基础篇之系统中141种颜色

    WPF最大的特点就是酷炫的外观,在学习过程中经常看见各种渐变窗体。作为几乎没做过美工的程序员,我对各种颜色的argb值不熟,颜色的英文单词也只认识部分。为了不至于每次都用Colors点出颜色再随机挑选看效果。写了个小程序展示System.Windows.Media.Colors中定义的141中颜色:

    前台代码:

    <Window x:Class="IOC.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <WrapPanel Name="wp"></WrapPanel>
    </Window>

    后台代码:

        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                IniWindow();
                IniWrapPanel();
            }
    
            /// <summary>
            /// 创建各种颜色的Lable,用以展示。
            /// </summary>
            /// <param name="lblColor">要创建的Label的颜色</param>
            /// <returns></returns>
            public static Label Createlbl(Color lblColor)
            {
                Label lbl = new Label();
                lbl.Height = 30;
                lbl.Width = 100;
                SolidColorBrush scb = new SolidColorBrush(lblColor);
                lbl.Background = scb;
                return lbl;
            }
    
            /// <summary>
            /// 初始化WrapPanel,其内容是各色标签。
            /// </summary>
            public void IniWrapPanel()
            {
                Type t = typeof(Colors);
                PropertyInfo[] pInfo = t.GetProperties();
                foreach (PropertyInfo pi in pInfo)
                {
                    Color c = (Color)ColorConverter.ConvertFromString(pi.Name);
                    Label lbl = Createlbl(c);
                    lbl.Content = pi.Name;
                    this.wp.Children.Add(lbl);
                }
            }
    
            /// <summary>
            /// 初始化窗体,以合理的尺寸显示各种颜色。
            /// </summary>
            public void IniWindow()
            {
                this.Title = "ColorPresentation";
                this.ResizeMode = ResizeMode.NoResize;
                this.Height = 600;
                this.Width = 820;
                this.Content = wp;
            }
        }

     展示效果:

  • 相关阅读:
    #JavaScript 闭包问题详解 #打倒心魔
    Typora + cnblog 图片自动上传 (超详细哦)
    #FUNCTION#CALL对象中的函数内作用域问题.md
    #windows #Github #HOST
    #######对象迭代器######
    #为什么不建议使用for...in 去遍历数组
    #前后端附件传输,去重的一种方式#解决方案
    #页面滚动刷新的实现原理 #下拉刷新#上拉刷新#drag to fresh
    自己动手实现一个阻塞队列
    APC注入
  • 原文地址:https://www.cnblogs.com/zty1294625258/p/6020064.html
Copyright © 2011-2022 走看看