WPF 颜色

来源:互联网 发布:java 函数形参和实参 编辑:程序博客网 时间:2024/04/30 18:14

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

运行结果:

WPF学习之颜色篇 - 一个半天 - You Got it!

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Media;using System.Windows.Controls;using System.Reflection;namespace PrintColors{    class Program    {        private static Window win = new Window();        private static WrapPanel wp = new WrapPanel();        [STAThread]        static void Main(string[] args)        {            IniWindow();            IniWrapPanel();            Application app = new Application();            app.Run(win);        }        /// <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 static 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;                wp.Children.Add(lbl);            }        }        /// <summary>        /// 初始化窗体,以合理的尺寸显示各种颜色。        /// </summary>        public static void IniWindow()        {            win.Title = "ColorPresentation";            win.ResizeMode = ResizeMode.NoResize;            win.Height = 600;            win.Width = 820;            win.Content = wp;        }    }}


0 0
原创粉丝点击