Known Colors : 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 
Known Colors
Known Colors
 
/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace KnownColors
{
    /// <summary>
    /// Summary description for KnownColors.
    /// </summary>
    public class KnownColors : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ComboBox comboBox1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        ArrayList cAL;
        ArrayList cNAL;

        public KnownColors()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            
            this.Text = "Known non-system colors";
            
            cAL = new ArrayList();      // colors
            cNAL = new ArrayList();      // strings
            NonSystemColors(cAL, cNAL);
            this.comboBox1.Sorted = true;
            this.comboBox1.DataSource = cNAL; //set the combo's data source

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // comboBox1
            // 
            this.comboBox1.Location = new System.Drawing.Point(88);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(12121);
            this.comboBox1.TabIndex = 0;
            this.comboBox1.Text = "comboBox1";
            // 
            // KnownColors
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(513);
            this.ClientSize = new System.Drawing.Size(292266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.comboBox1});
            this.Name = "KnownColors";
            this.Text = "KnownColors";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new KnownColors());
        }
        private void NonSystemColors(ArrayList cAL, ArrayList cNAL)
        {
            Array cA = Enum.GetValues(typeof(KnownColor));
            foreach(KnownColor knwnC in cA)  // cX.Length = 167
            {
                Color curC = Color.FromKnownColor(knwnC)
                if(!curC.IsSystemColor
                {
                    cAL.Add(curC);
                    cNAL.Add(curC.Name.ToString());
                }
            }
        }
        protected override void OnPaint(PaintEventArgs pea)
        {
            Graphics g = pea.Graphics;
            int wi = 70, hi = 12, rectNb = 8
            int cALNb = cAL.Count;

            this.Width = (wi +2)*rectNb + 9;
            int y = (int)(cALNb / rectNb);
            this.Height = y*(+ hi60;

            DisplayKnownColors(g, cALNb, wi, hi, rectNb);
            g.Dispose();
        }
        private void DisplayKnownColors(Graphics g, int cALNb, int wi, int hi, int rectNb)
        {
            Rectangle rec;
            Pen p = new Pen(this.ForeColor);
            Brush b;

            StringFormat strfmt = new StringFormat();
            strfmt.LineAlignment = strfmt.Alignment = StringAlignment.Near;

            int x, y;
            for (int i = 0; i < cALNb; i++)
            {
                x = (int)(i % rectNb);
                y = (int)(i / rectNb);
                rec = new Rectangle(+ x*(+ wi)+ y*(+ hi), wi, hi);

                g.DrawRectangle(p, rec);
                b  = new SolidBrush((Color)cAL[i]);
                g.FillRectangle(b, rec);

                b  = new SolidBrush(Color.Black);
                g.DrawString((string)cNAL[i]this.Font, b, rec, strfmt);
            }
            x = (int)(cALNb % rectNb);
            y = (int)(cALNb / rectNb);
            this.comboBox1.Location = new Point(x*(wi + 22, y*(+ hi2);
        }
    }
}


           
         
  
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.Color ChangerColor Changer
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.