Color Converter : Color Dialog « GUI Windows Form « 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 » GUI Windows Form » Color DialogScreenshots 
Color Converter
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
//

class Form1 : Form {
    private Color theColor;

    public Form1() {
        InitializeComponent();
        tbRed.Text = "0";
        tbGreen.Text = "0";
        tbBlue.Text = "0";
    }

    private void parseRGB() {
        int r, g, b;

        r = Int16.Parse(tbRed.Text);
        r = Math.Min(r, 255);
        g = Int16.Parse(tbGreen.Text);
        g = Math.Min(g, 255);
        b = Int16.Parse(tbBlue.Text);
        b = Math.Min(b, 255);
        theColor = Color.FromArgb(r, g, b);
        tbHue.Text = theColor.GetHue().ToString();
        tbSat.Text = theColor.GetSaturation().ToString();
        tbBright.Text = theColor.GetBrightness().ToString();
        this.Invalidate();
    }

    private void tbRed_TextChanged(object sender, EventArgs e) {
        parseRGB();
    }

    private void tbGreen_TextChanged(object sender, EventArgs e) {
        parseRGB();
    }

    private void tbBlue_TextChanged(object sender, EventArgs e) {
        parseRGB();
    }

    private void Form1_Paint(object sender, PaintEventArgs e) {
        Graphics g = e.Graphics;

        SolidBrush backBrush = new SolidBrush(System.Drawing.SystemColors.Control);
        g.FillRectangle(backBrush, this.ClientRectangle);
        backBrush.Dispose();

        Rectangle r = new Rectangle(108010040);
        SolidBrush b = new SolidBrush(theColor);
        g.SetClip(this.ClientRectangle);
        g.FillRectangle(b, r);
        b.Dispose();
    }
    private void InitializeComponent() {
        this.tbRed = new System.Windows.Forms.TextBox();
        this.tbGreen = new System.Windows.Forms.TextBox();
        this.label1 = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.tbBlue = new System.Windows.Forms.TextBox();
        this.tbHue = new System.Windows.Forms.TextBox();
        this.tbSat = new System.Windows.Forms.TextBox();
        this.label4 = new System.Windows.Forms.Label();
        this.label5 = new System.Windows.Forms.Label();
        this.label6 = new System.Windows.Forms.Label();
        this.tbBright = new System.Windows.Forms.TextBox();
        this.SuspendLayout();
        // 
        // tbRed
        // 
        this.tbRed.Location = new System.Drawing.Point(4510);
        this.tbRed.Name = "tbRed";
        this.tbRed.Size = new System.Drawing.Size(4720);
        this.tbRed.TabIndex = 1;
        this.tbRed.TextChanged += new System.EventHandler(this.tbRed_TextChanged);
        // 
        // tbGreen
        // 
        this.tbGreen.Location = new System.Drawing.Point(14910);
        this.tbGreen.Name = "tbGreen";
        this.tbGreen.Size = new System.Drawing.Size(4720);
        this.tbGreen.TabIndex = 2;
        this.tbGreen.TextChanged += new System.EventHandler(this.tbGreen_TextChanged);
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(1313);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(2514);
        this.label1.TabIndex = 8;
        this.label1.Text = "Red";
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(10613);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(3614);
        this.label2.TabIndex = 9;
        this.label2.Text = "Green";
        // 
        // label3
        // 
        this.label3.AutoSize = true;
        this.label3.Location = new System.Drawing.Point(21213);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(2714);
        this.label3.TabIndex = 10;
        this.label3.Text = "Blue";
        // 
        // tbBlue
        // 
        this.tbBlue.Location = new System.Drawing.Point(24610);
        this.tbBlue.Name = "tbBlue";
        this.tbBlue.Size = new System.Drawing.Size(4720);
        this.tbBlue.TabIndex = 3;
        this.tbBlue.TextChanged += new System.EventHandler(this.tbBlue_TextChanged);
        // 
        // tbHue
        // 
        this.tbHue.Location = new System.Drawing.Point(4544);
        this.tbHue.Name = "tbHue";
        this.tbHue.ReadOnly = true;
        this.tbHue.Size = new System.Drawing.Size(4720);
        this.tbHue.TabIndex = 4;
        // 
        // tbSat
        // 
        this.tbSat.Location = new System.Drawing.Point(14944);
        this.tbSat.Name = "tbSat";
        this.tbSat.ReadOnly = true;
        this.tbSat.Size = new System.Drawing.Size(4720);
        this.tbSat.TabIndex = 5;
        // 
        // label4
        // 
        this.label4.AutoSize = true;
        this.label4.Location = new System.Drawing.Point(1347);
        this.label4.Name = "label4";
        this.label4.Size = new System.Drawing.Size(2514);
        this.label4.TabIndex = 11;
        this.label4.Text = "Hue";
        // 
        // label5
        // 
        this.label5.AutoSize = true;
        this.label5.Location = new System.Drawing.Point(12145);
        this.label5.Name = "label5";
        this.label5.Size = new System.Drawing.Size(2114);
        this.label5.TabIndex = 12;
        this.label5.Text = "Sat";
        // 
        // label6
        // 
        this.label6.AutoSize = true;
        this.label6.Location = new System.Drawing.Point(20547);
        this.label6.Name = "label6";
        this.label6.Size = new System.Drawing.Size(3414);
        this.label6.TabIndex = 13;
        this.label6.Text = "Bright";
        // 
        // tbBright
        // 
        this.tbBright.Location = new System.Drawing.Point(24642);
        this.tbBright.Name = "tbBright";
        this.tbBright.ReadOnly = true;
        this.tbBright.Size = new System.Drawing.Size(4720);
        this.tbBright.TabIndex = 6;
        // 
        // Form1
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(513);
        this.ClientSize = new System.Drawing.Size(431217);
        this.Controls.Add(this.tbBright);
        this.Controls.Add(this.tbBlue);
        this.Controls.Add(this.label6);
        this.Controls.Add(this.label5);
        this.Controls.Add(this.label4);
        this.Controls.Add(this.label3);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.tbSat);
        this.Controls.Add(this.tbHue);
        this.Controls.Add(this.tbGreen);
        this.Controls.Add(this.tbRed);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    private System.Windows.Forms.TextBox tbRed;
    private System.Windows.Forms.TextBox tbGreen;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox tbBlue;
    private System.Windows.Forms.TextBox tbHue;
    private System.Windows.Forms.TextBox tbSat;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.Label label5;
    private System.Windows.Forms.Label label6;
    private System.Windows.Forms.TextBox tbBright;
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}

 
Related examples in the same category
1.Click on me to change the colorClick on me to change the color
2.Display color dialog and get user selectionDisplay color dialog and get user selection
3.Color Dialog and Font DialogColor Dialog and Font Dialog
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.