Get all known color : Color « 2D Graphics « C# / C Sharp





Get all known color

    

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

public class Form1 : System.Windows.Forms.Form {
    ArrayList knownColorList = new ArrayList();
    ArrayList knownColorNameList = new ArrayList();

    public Form1() {
        NonSystemColors(knownColorList, knownColorNameList);

    }
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    private void NonSystemColors(ArrayList knownColorList, ArrayList knownColorNameList) {
        Array cA = Enum.GetValues(typeof(KnownColor));
        foreach (KnownColor knwnC in cA) {
            Color curC = Color.FromKnownColor(knwnC);
            if (!curC.IsSystemColor) {
                knownColorList.Add(curC);
                knownColorNameList.Add(curC.Name.ToString());
            }
        }
    }
    protected override void OnPaint(PaintEventArgs pea) {
        Graphics g = pea.Graphics;
        int wi = 70, hi = 12, rectNb = 8;
        int count = knownColorList.Count;

        this.Width = (wi + 2) * rectNb + 9;
        int y = (int)(count / rectNb);
        this.Height = y * (2 + hi) + 60;

        DisplayKnownColors(g, count, wi, hi, rectNb);
        g.Dispose();
    }
    private void DisplayKnownColors(Graphics g, int count, 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 < count; i++) {
            x = (int)(i % rectNb);
            y = (int)(i / rectNb);
            rec = new Rectangle(1 + x * (2 + wi), 1 + y * (2 + hi), wi, hi);

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

            b = new SolidBrush(Color.Black);
            g.DrawString((string)knownColorNameList[i], this.Font, b, rec, strfmt);
        }
    }
}

   
    
    
  










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.Known ColorsKnown Colors
8.Five yellow squares with different alpha values(Transparensy)
9.Create two color instances with different alpha components
10.Color.Chocolate
11.Use Color.FromArgb to create 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