Monday, November 23, 2009

How to enumerate known system colors

Use the System.Drawing.KnownColor enumerator.

The following example prints all known system color names and RGB values:

using System.Drawing;
 
...
 
Array knownColors = Enum.GetValues(typeof(KnownColor));
foreach (KnownColor knownColor in knownColors)
{
    String knownColorName = knownColor.ToString();
    Color color = Color.FromKnownColor(knownColor);
    SolidBrush solidBrush = new SolidBrush(color);
 
    Console.WriteLine("{0}: {1:X2}, {2:X2}, {3:X2}",
        knownColorName, color.R, color.G, color.B);
}

No comments:

Post a Comment