Color Changer : Color « 2D Graphics « C# / C Sharp






Color Changer

Color Changer
   
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ColorChanger
{
    public class ColorChanger : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Label lblSaturation;
        internal System.Windows.Forms.Label lblHue;
        internal System.Windows.Forms.Label lblBrightness;
        internal System.Windows.Forms.Label Label1;
        internal System.Windows.Forms.ListBox lstColors;

        private System.ComponentModel.Container components = null;

        public ColorChanger()
        {
            InitializeComponent();
        }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        private void InitializeComponent()
        {
            this.lblSaturation = new System.Windows.Forms.Label();
            this.lblHue = new System.Windows.Forms.Label();
            this.lblBrightness = new System.Windows.Forms.Label();
            this.Label1 = new System.Windows.Forms.Label();
            this.lstColors = new System.Windows.Forms.ListBox();
            this.SuspendLayout();

            this.lblSaturation.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.lblSaturation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.lblSaturation.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.lblSaturation.Location = new System.Drawing.Point(264, 56);
            this.lblSaturation.Name = "lblSaturation";
            this.lblSaturation.Size = new System.Drawing.Size(136, 20);
            this.lblSaturation.TabIndex = 9;
            this.lblSaturation.Text = " Saturation";

            this.lblHue.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.lblHue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.lblHue.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.lblHue.Location = new System.Drawing.Point(264, 32);
            this.lblHue.Name = "lblHue";
            this.lblHue.Size = new System.Drawing.Size(136, 20);
            this.lblHue.TabIndex = 8;
            this.lblHue.Text = " Hue";

            this.lblBrightness.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.lblBrightness.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.lblBrightness.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.lblBrightness.Location = new System.Drawing.Point(264, 8);
            this.lblBrightness.Name = "lblBrightness";
            this.lblBrightness.Size = new System.Drawing.Size(136, 20);
            this.lblBrightness.TabIndex = 7;
            this.lblBrightness.Text = " Brightness";

            this.Label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.Label1.Location = new System.Drawing.Point(8, 8);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(200, 20);
            this.Label1.TabIndex = 6;
            this.Label1.Text = " Choose a Background Color:";

            this.lstColors.Location = new System.Drawing.Point(8, 36);
            this.lstColors.Name = "lstColors";
            this.lstColors.Size = new System.Drawing.Size(200, 238);
            this.lstColors.TabIndex = 5;
            this.lstColors.SelectedIndexChanged += new System.EventHandler(this.lstColors_SelectedIndexChanged);

            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(472, 290);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.lblSaturation,
                                                                          this.lblHue,
                                                                          this.lblBrightness,
                                                                          this.Label1,
                                                                          this.lstColors});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "ColorChanger";
            this.Text = "Color Changer";
            this.Load += new System.EventHandler(this.ColorChanger_Load);
            this.ResumeLayout(false);

        }
        #endregion
        [STAThread]
        static void Main() 
        {
            Application.Run(new ColorChanger());
        }

        private void ColorChanger_Load(object sender, System.EventArgs e)
        {
            string[] colorNames;
            colorNames = System.Enum.GetNames(typeof(KnownColor));

            lstColors.Items.AddRange(colorNames);
        }

        private void lstColors_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            KnownColor selectedColor;
            selectedColor = (KnownColor)System.Enum.Parse(typeof(KnownColor), lstColors.Text);
            
            this.BackColor = System.Drawing.Color.FromKnownColor(selectedColor);
            
            lblBrightness.Text = "Brightness = " +this.BackColor.GetBrightness().ToString();
            lblHue.Text = "Hue = " + this.BackColor.GetHue().ToString();
            lblSaturation.Text = "Saturation = " + this.BackColor.GetSaturation().ToString();
        }
    }
}


           
         
    
    
  








Related examples in the same category

1.Transparent colorTransparent color
2.List all known color in a systemList all known color in a system
3.Draw each of 100 cells with randomly chosen colorsDraw each of 100 cells with randomly chosen colors
4.Filled with the semi transparent and transparent colorFilled with the semi transparent and transparent color
5.All the colors that are supported in C# according
6.Known ColorsKnown Colors
7.Five yellow squares with different alpha values(Transparensy)
8.Create two color instances with different alpha components
9.Color.Chocolate
10.Use Color.FromArgb to create Color
11.Get all known color
12.Color representation in r,g,b with values [0.0 - 1.0].
13.Color representation in h,s,v with h = [0 - 360], s,v = [0.0 - 1.0].
14.Return a randomly-generated color
15.Color to RGB value
16.Get color outof String
17.Parse Color
18.Color To Rgb
19.Rgb To Color
20.Returns an HTML #XXXXXX format for a color.
21.Convert color name to Color object
22.Hex Color Util
23.Helper method to get a color based on it's string value
24.Converts a color string to a hex value string
25.Color to Hue,Lightness,Saturation value
26.Get Color From String
27.Convert String value To Color
28.Color to String
29.Masks an image and returns a two color bitmap.
30.Convert Hex To Color
31.Create Color From HLS value
32.Parse Color with Color.FromArgb
33.Create Color Object from RGB value
34.Get Rainbow Colors
35.Convert RGB to HSL
36.HSL to RGB conversion.
37.Hsv To Rgb
38.Rgb Linear Interpolate
39.Get Luminance
40.To Grey scale
41.Heat Map background colour calculations