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="" Width="">
<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 = ;
lbl.Width = ;
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 = ;
this.Width = ;
this.Content = wp;
}
}

展示效果:

最新文章

  1. centos下python中添加easygui模块
  2. django常见小问题收集(转)
  3. lisp中的nil
  4. google 语音api
  5. HTTP协议开发应用-文件服务器
  6. Property ClientHeight does not exist 问题解决
  7. 【PRML读书笔记-Chapter1-Introduction】1.4 The Curse of Dimensionality
  8. css构造文本
  9. delphi 常用属性+方法+事件+代码+函数
  10. Java如何等待子线程执行结束
  11. linux c coding style
  12. zoj 1730 / poj 1455 Crazy Tea Party
  13. FTP的主动和被动模式详解
  14. Coroutine的原理以及实现
  15. failed to create process怎么解决
  16. 全国大学API接口分享
  17. Lua常用时间函数
  18. opencv-python 学习初探1
  19. C# 获取文件夹下的所有文件夹及其文件
  20. PAT乙级1009

热门文章

  1. HDU 3032 Nim or not Nim? [Multi-SG]
  2. BZOJ 1434: [ZJOI2009]染色游戏
  3. 2018/1/15 JAVA多线程相关
  4. ES6 学习笔记之一 块作用域与let和const
  5. SynchronousQueue 的联想
  6. 017 Java中的静态代理、JDK动态代理、cglib动态代理
  7. cloud9 ide
  8. Spring Data与elasticsearch版本对应关系
  9. c中有序表的简单定义
  10. 老男孩Python全栈开发(92天全)视频教程 自学笔记21