本文主要介绍了C# 枚举Color并展示各种颜色效果,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧
本文主要介绍了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# 枚举颜色内容请搜索得得之家以前的文章希望大家以后多多支持得得之家!
沃梦达教程
本文标题为:C# 枚举Color并展示各种颜色效果的示例
基础教程推荐
猜你喜欢
- C#类和结构详解 2023-05-30
- C#控制台实现飞行棋小游戏 2023-04-22
- C# windows语音识别与朗读实例 2023-04-27
- 一个读写csv文件的C#类 2022-11-06
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- winform把Office转成PDF文件 2023-06-14
- ZooKeeper的安装及部署教程 2023-01-22
- unity实现动态排行榜 2023-04-27
- C# 调用WebService的方法 2023-03-09
- C# List实现行转列的通用方案 2022-11-02