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

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » ColorScreenshots 
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 Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #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(26456);
            this.lblSaturation.Name = "lblSaturation";
            this.lblSaturation.Size = new System.Drawing.Size(13620);
            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(26432);
            this.lblHue.Name = "lblHue";
            this.lblHue.Size = new System.Drawing.Size(13620);
            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(2648);
            this.lblBrightness.Name = "lblBrightness";
            this.lblBrightness.Size = new System.Drawing.Size(13620);
            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(88);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(20020);
            this.Label1.TabIndex = 6;
            this.Label1.Text = " Choose a Background Color:";

            this.lstColors.Location = new System.Drawing.Point(836);
            this.lstColors.Name = "lstColors";
            this.lstColors.Size = new System.Drawing.Size(200238);
            this.lstColors.TabIndex = 5;
            this.lstColors.SelectedIndexChanged += new System.EventHandler(this.lstColors_SelectedIndexChanged);

            this.AutoScaleBaseSize = new System.Drawing.Size(514);
            this.ClientSize = new System.Drawing.Size(472290);
            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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.