C # enumerates colors and shows examples of various color effects

Time:2021-9-26

This article mainly introduces c# enumerating colors and shows various color effects, which are shared with you as follows:

This method enumerates colors to show the effects of each color, which is convenient to select the appropriate color for the control. This example needs to be used in a form project and displayed by creating a listview control. The code is as follows:


        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;
        }

This is the end of this article about c# enumerating colors and showing examples of various color effects. For more information about c# enumerating colors, please search previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!

Recommended Today

Supervisor

Supervisor [note] Supervisor – H view supervisor command help Supervisorctl – H view supervisorctl command help Supervisorctl help view the action command of supervisorctl Supervisorctl help any action to view the use of this action 1. Introduction Supervisor is a process control system. Generally speaking, it can monitor your process. If the process exits abnormally, […]