WPF中的颜色值-学习

85cd8d5cdf488fbdee10f37dc879392c.png

源码:
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);
        }

        /// 
        /// 创建各种颜色的Lable,用以展示。
        /// 
        /// 要创建的Label的颜色
        /// 
        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;
        }
        /// 
        /// 初始化WrapPanel,其内容是各色标签。
        /// 
        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);
            }
        }
        /// 
        /// 初始化窗体,以合理的尺寸显示各种颜色。
        /// 
        public static void IniWindow()
        {
            win.Title = "ColorPresentation";
            win.ResizeMode = ResizeMode.NoResize;
            win.Height = 600;
            win.Width = 820;
            win.Content = wp;
        }
    }
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23109131/viewspace-702697/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23109131/viewspace-702697/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值