C#|C# 枚举Color并展示各种颜色效果的示例
本文主要介绍了C# 枚举Color并展示各种颜色效果,分享给大家,具体如下:
【C#|C# 枚举Color并展示各种颜色效果的示例】
文章图片
本方法枚举Color以展示各颜色效果,方便为控件选择合适的颜色。本例需要在窗体项目中使用,通过创建ListView控件展示,代码如下:
private void displayColor(){Control listControl = this.Controls["listView_Color"]; if (listControl != null){listControl.Visible = true; return; }ListView listView_Color = new ListView(); System.Windows.Forms.ColumnHeader columnHeaderA = new System.Windows.Forms.ColumnHeader(); System.Windows.Forms.ColumnHeader columnHeaderB = new System.Windows.Forms.ColumnHeader(); System.Windows.Forms.ColumnHeader columnHeaderC = new System.Windows.Forms.ColumnHeader(); System.Windows.Forms.ColumnHeader columnHeaderD = new System.Windows.Forms.ColumnHeader(); System.Windows.Forms.ColumnHeader columnHeaderE = new System.Windows.Forms.ColumnHeader(); System.Windows.Forms.ColumnHeader columnHeaderF = new System.Windows.Forms.ColumnHeader(); columnHeaderA.Width = 200; listView_Color.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {columnHeaderA,columnHeaderB,columnHeaderC,columnHeaderD,columnHeaderE,columnHeaderF}); string[] strArr = new string[6]; System.Array colorsArray = Enum.GetValues(typeof(System.Drawing.KnownColor)); for (int i = 0; i < colorsArray.Length; i++){string colorName = colorsArray.GetValue(i).ToString(); //if (colorName.Contains("Green")){System.Drawing.Color color = System.Drawing.Color.FromName(colorName); for (int j = 0; j < 6; j++)strArr[j] = colorName; ListViewItem li = new ListViewItem(strArr); li.ForeColor = color; listView_Color.Items.Add(li); li = new ListViewItem(strArr); li.BackColor = color; listView_Color.Items.Add(li); li = new ListViewItem(strArr); li.BackColor = color; li.ForeColor = System.Drawing.Color.White; listView_Color.Items.Add(li); }}this.Controls.Add(listView_Color); listView_Color.BringToFront(); listView_Color.Dock = DockStyle.Fill; listView_Color.View = System.Windows.Forms.View.Details; columnHeaderF.Width = listView_Color.DisplayRectangle.Width - columnHeaderA.Width - columnHeaderB.Width - columnHeaderC.Width - columnHeaderD.Width - columnHeaderE.Width; listView_Color.Name = "listView_Color"; }private void hideColor(){Control listControl = this.Controls["listView_Color"]; if(listControl!=null)listControl.Visible = false; }
到此这篇关于C# 枚举Color并展示各种颜色效果的示例的文章就介绍到这了,更多相关C# 枚举颜色内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- Java并发编程异步操作Future和FutureTask
- Java数据结构之并查集的实现
- java并查集算法带你领略热血江湖
- Java实现并查集示例详解
- 论文回顾(Batch Augmentation,在批次中进行数据扩充可以减少训练时间并提高泛化能力)
- Python爬取百度春节祝福语并生成心形词云
- 为什么我建议线上高并发量的日志输出的时候不能带有代码位置
- Web3|Web3js获取MetaMask钱包并监听切换
- 百度Paddle速查_CPU和GPU的mnist预测训练_模型导出_模型导入再预测_导出onnx并预测
- 图论|判断图连通性的三种方法(并查集/dfs/bfs)