发布于2021-07-18 19:42 阅读(1008) 评论(0) 点赞(22) 收藏(5)
本方法枚举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;
- }
原文链接:https://blog.csdn.net/lzl_li/article/details/117922098
作者:风雨雷电
链接:http://www.pythonpdf.com/blog/article/87/f8477e63cadb5e71fc7e/
来源:编程知识网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!