KnownColor Enumeration
.NET Framework 4
Specifies the known system colors.
Assembly: System.Drawing (in System.Drawing.dll)
| Member name | Description | |
|---|---|---|
| ActiveBorder | The system-defined color of the active window's border. | |
| ActiveCaption | The system-defined color of the background of the active window's title bar. | |
| ActiveCaptionText | The system-defined color of the text in the active window's title bar. | |
| AppWorkspace | The system-defined color of the application workspace. The application workspace is the area in a multiple-document view that is not being occupied by documents. | |
| Control | The system-defined face color of a 3-D element. | |
| ControlDark | The system-defined shadow color of a 3-D element. The shadow color is applied to parts of a 3-D element that face away from the light source. | |
| ControlDarkDark | The system-defined color that is the dark shadow color of a 3-D element. The dark shadow color is applied to the parts of a 3-D element that are the darkest color. | |
| ControlLight | The system-defined color that is the light color of a 3-D element. The light color is applied to parts of a 3-D element that face the light source. | |
| ControlLightLight | The system-defined highlight color of a 3-D element. The highlight color is applied to the parts of a 3-D element that are the lightest color. | |
| ControlText | The system-defined color of text in a 3-D element. | |
| Desktop | The system-defined color of the desktop. | |
| GrayText | The system-defined color of dimmed text. Items in a list that are disabled are displayed in dimmed text. | |
| Highlight | The system-defined color of the background of selected items. This includes selected menu items as well as selected text. | |
| HighlightText | The system-defined color of the text of selected items. | |
| HotTrack | The system-defined color used to designate a hot-tracked item. Single-clicking a hot-tracked item executes the item. | |
| InactiveBorder | The system-defined color of an inactive window's border. | |
| InactiveCaption | The system-defined color of the background of an inactive window's title bar. | |
| InactiveCaptionText | The system-defined color of the text in an inactive window's title bar. | |
| Info | The system-defined color of the background of a ToolTip. | |
| InfoText | The system-defined color of the text of a ToolTip. | |
| Menu | The system-defined color of a menu's background. | |
| MenuText | The system-defined color of a menu's text. | |
| ScrollBar | The system-defined color of the background of a scroll bar. | |
| Window | The system-defined color of the background in the client area of a window. | |
| WindowFrame | The system-defined color of a window frame. | |
| WindowText | The system-defined color of the text in the client area of a window. | |
| Transparent | A system-defined color. | |
| AliceBlue | A system-defined color. | |
| AntiqueWhite | A system-defined color. | |
| Aqua | A system-defined color. | |
| Aquamarine | A system-defined color. | |
| Azure | A system-defined color. | |
| Beige | A system-defined color. | |
| Bisque | A system-defined color. | |
| Black | A system-defined color. | |
| BlanchedAlmond | A system-defined color. | |
| Blue | A system-defined color. | |
| BlueViolet | A system-defined color. | |
| Brown | A system-defined color. | |
| BurlyWood | A system-defined color. | |
| CadetBlue | A system-defined color. | |
| Chartreuse | A system-defined color. | |
| Chocolate | A system-defined color. | |
| Coral | A system-defined color. | |
| CornflowerBlue | A system-defined color. | |
| Cornsilk | A system-defined color. | |
| Crimson | A system-defined color. | |
| Cyan | A system-defined color. | |
| DarkBlue | A system-defined color. | |
| DarkCyan | A system-defined color. | |
| DarkGoldenrod | A system-defined color. | |
| DarkGray | A system-defined color. | |
| DarkGreen | A system-defined color. | |
| DarkKhaki | A system-defined color. | |
| DarkMagenta | A system-defined color. | |
| DarkOliveGreen | A system-defined color. | |
| DarkOrange | A system-defined color. | |
| DarkOrchid | A system-defined color. | |
| DarkRed | A system-defined color. | |
| DarkSalmon | A system-defined color. | |
| DarkSeaGreen | A system-defined color. | |
| DarkSlateBlue | A system-defined color. | |
| DarkSlateGray | A system-defined color. | |
| DarkTurquoise | A system-defined color. | |
| DarkViolet | A system-defined color. | |
| DeepPink | A system-defined color. | |
| DeepSkyBlue | A system-defined color. | |
| DimGray | A system-defined color. | |
| DodgerBlue | A system-defined color. | |
| Firebrick | A system-defined color. | |
| FloralWhite | A system-defined color. | |
| ForestGreen | A system-defined color. | |
| Fuchsia | A system-defined color. | |
| Gainsboro | A system-defined color. | |
| GhostWhite | A system-defined color. | |
| Gold | A system-defined color. | |
| Goldenrod | A system-defined color. | |
| Gray | A system-defined color. | |
| Green | A system-defined color. | |
| GreenYellow | A system-defined color. | |
| Honeydew | A system-defined color. | |
| HotPink | A system-defined color. | |
| IndianRed | A system-defined color. | |
| Indigo | A system-defined color. | |
| Ivory | A system-defined color. | |
| Khaki | A system-defined color. | |
| Lavender | A system-defined color. | |
| LavenderBlush | A system-defined color. | |
| LawnGreen | A system-defined color. | |
| LemonChiffon | A system-defined color. | |
| LightBlue | A system-defined color. | |
| LightCoral | A system-defined color. | |
| LightCyan | A system-defined color. | |
| LightGoldenrodYellow | A system-defined color. | |
| LightGray | A system-defined color. | |
| LightGreen | A system-defined color. | |
| LightPink | A system-defined color. | |
| LightSalmon | A system-defined color. | |
| LightSeaGreen | A system-defined color. | |
| LightSkyBlue | A system-defined color. | |
| LightSlateGray | A system-defined color. | |
| LightSteelBlue | A system-defined color. | |
| LightYellow | A system-defined color. | |
| Lime | A system-defined color. | |
| LimeGreen | A system-defined color. | |
| Linen | A system-defined color. | |
| Magenta | A system-defined color. | |
| Maroon | A system-defined color. | |
| MediumAquamarine | A system-defined color. | |
| MediumBlue | A system-defined color. | |
| MediumOrchid | A system-defined color. | |
| MediumPurple | A system-defined color. | |
| MediumSeaGreen | A system-defined color. | |
| MediumSlateBlue | A system-defined color. | |
| MediumSpringGreen | A system-defined color. | |
| MediumTurquoise | A system-defined color. | |
| MediumVioletRed | A system-defined color. | |
| MidnightBlue | A system-defined color. | |
| MintCream | A system-defined color. | |
| MistyRose | A system-defined color. | |
| Moccasin | A system-defined color. | |
| NavajoWhite | A system-defined color. | |
| Navy | A system-defined color. | |
| OldLace | A system-defined color. | |
| Olive | A system-defined color. | |
| OliveDrab | A system-defined color. | |
| Orange | A system-defined color. | |
| OrangeRed | A system-defined color. | |
| Orchid | A system-defined color. | |
| PaleGoldenrod | A system-defined color. | |
| PaleGreen | A system-defined color. | |
| PaleTurquoise | A system-defined color. | |
| PaleVioletRed | A system-defined color. | |
| PapayaWhip | A system-defined color. | |
| PeachPuff | A system-defined color. | |
| Peru | A system-defined color. | |
| Pink | A system-defined color. | |
| Plum | A system-defined color. | |
| PowderBlue | A system-defined color. | |
| Purple | A system-defined color. | |
| Red | A system-defined color. | |
| RosyBrown | A system-defined color. | |
| RoyalBlue | A system-defined color. | |
| SaddleBrown | A system-defined color. | |
| Salmon | A system-defined color. | |
| SandyBrown | A system-defined color. | |
| SeaGreen | A system-defined color. | |
| SeaShell | A system-defined color. | |
| Sienna | A system-defined color. | |
| Silver | A system-defined color. | |
| SkyBlue | A system-defined color. | |
| SlateBlue | A system-defined color. | |
| SlateGray | A system-defined color. | |
| Snow | A system-defined color. | |
| SpringGreen | A system-defined color. | |
| SteelBlue | A system-defined color. | |
| Tan | A system-defined color. | |
| Teal | A system-defined color. | |
| Thistle | A system-defined color. | |
| Tomato | A system-defined color. | |
| Turquoise | A system-defined color. | |
| Violet | A system-defined color. | |
| Wheat | A system-defined color. | |
| White | A system-defined color. | |
| WhiteSmoke | A system-defined color. | |
| Yellow | A system-defined color. | |
| YellowGreen | A system-defined color. | |
| ButtonFace | The system-defined face color of a 3-D element. | |
| ButtonHighlight | The system-defined color that is the highlight color of a 3-D element. This color is applied to parts of a 3-D element that face the light source. | |
| ButtonShadow | The system-defined color that is the shadow color of a 3-D element. This color is applied to parts of a 3-D element that face away from the light source. | |
| GradientActiveCaption | The system-defined color of the lightest color in the color gradient of an active window's title bar. | |
| GradientInactiveCaption | The system-defined color of the lightest color in the color gradient of an inactive window's title bar. | |
| MenuBar | The system-defined color of the background of a menu bar. | |
| MenuHighlight | The system-defined color used to highlight menu items when the menu appears as a flat menu. |
The following code example demonstrates how to use the KnownColor enumeration to print out the names and colors of all its values. This example is designed to be used with Windows Forms. Create a form and paste the following code into it. Call the DisplayKnownColors method in the form's Paint event-handling method, passing e as PaintEventArgs.
private void DisplayKnownColors(PaintEventArgs e) { this.Size = new Size(650, 550); // Get all the values from the KnownColor enumeration. System.Array colorsArray = Enum.GetValues(typeof(KnownColor)); KnownColor[] allColors = new KnownColor[colorsArray.Length]; Array.Copy(colorsArray, allColors, colorsArray.Length); // Loop through printing out the values' names in the colors // they represent. float y = 0; float x = 10.0F; for(int i = 0; i < allColors.Length; i++) { // If x is a multiple of 30, start a new column. if (i > 0 && i % 30 == 0) { x += 105.0F; y = 15.0F; } else { // Otherwise, increment y by 15. y += 15.0F; } // Create a custom brush from the color and use it to draw // the brush's name. SolidBrush aBrush = new SolidBrush(Color.FromName(allColors[i].ToString())); e.Graphics.DrawString(allColors[i].ToString(), this.Font, aBrush, x, y); // Dispose of the custom brush. aBrush.Dispose(); } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Sample Using PowerShell
<#
.SYNOPSIS
This script shows formatting of enums
.DESCRIPTION
This script iteraties through two enums and uses
tostring and enum format strings to display
the enum's values.
.NOTES
File Name : Show-EnumFormat.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://www.pshscripts.blogspot.com
MSDN sample posted to:
http://msdn.microsoft.com/en-us/library/c3s1ez6e.aspx
.EXAMPLE
Psh> .\Show-EnumFormat.ps1
g f d x
Monday Monday 0 00000000
Tuesday Tuesday 1 00000001
Wednesday Wednesday 2 00000002
Thursday Thursday 3 00000003
Friday Friday 4 00000004
Saturday Saturday 5 00000005
Sunday Sunday 6 00000006
Default Default 7 00000007
#>
# Create Enum
$Enum = [system.windows.forms.day]
# Just in case
$t = [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
$t = [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
# loop through each enum and display the formatting
# Header rows
"Enum : {0}" -f $enum
"{0,9} {1,9} {2,4} {3,10}" -f "g", "f", "d", "x"
# Now display the formatted values
Foreach ($E in [System.enum]::getvalues($enum)) {
"{0,9} {1,9} {2,4} {3,10}" -f $e.tostring("g"),$e.tostring("f"),$e.tostring("d"), $e.tostring("x")
}
$Enum = [system.drawing.knowncolor]
# Just in case
$t = [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
$t = [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
# loop through each enum and display the formatting
# Header rows
"Enum : {0}" -f $enum
"{0,23} {1,23} {2,6} {3,10}" -f "g", "f", "d", "x"
# Now display the formatted values
Foreach ($E in [System.enum]::getvalues($enum)) {
"{0,23} {1,23} {2,6} {3,10}" -f $e.tostring("g"),$e.tostring("f"),$e.tostring("d"), $e.tostring("x")
}
- 11/10/2011
- Thomas Lee
nice improvement
"Improved C# example" is a nice improvement
- 6/21/2011
- JimmyTropo
- 6/21/2011
- JimmyTropo
Improved C# example ?
I could not read all the text for the colors because of the contrast. Slightly modified code below:
private void DisplayKnownColors(PaintEventArgs e)
{
this.Size = new Size(550, 760);
// Get all the values from the KnownColor enumeration.
System.Array colorsArray = Enum.GetValues(typeof(KnownColor));
KnownColor[] allColors = new KnownColor[colorsArray.Length];
Array.Copy(colorsArray, allColors, colorsArray.Length);
// Loop through printing out the values' names in the colors
// they represent.
float y = 0;
float x = 10.0F;
SolidBrush bBrush = new SolidBrush(Color.Black);
Pen p1 = new Pen(Color.Black);
for (int i = 0; i < allColors.Length; i++)
{
// If x is a multiple of 45, start a new column.
if (i > 0 && i % 45 == 0)
{
x += 130.0F;
y = 15.0F;
}
else
{
// Otherwise, increment y by 15.
y += 15.0F;
}
// Create a custom brush from the color and use it to draw
// the brush's name.
SolidBrush aBrush = new SolidBrush(Color.FromName(allColors[i].ToString()));
e.Graphics.DrawRectangle(p1, x, y, 13.0F, 13.0F);
e.Graphics.FillRectangle(aBrush, x + 1.0F, y + 1.0F, 12.0F, 12.0F);
e.Graphics.DrawString(allColors[i].ToString(), this.Font, bBrush, x + 14.0F, y);
// Dispose of the custom brush.
aBrush.Dispose();
}
bBrush.Dispose();
p1.Dispose();
}
private void DisplayKnownColors(PaintEventArgs e)
{
this.Size = new Size(550, 760);
// Get all the values from the KnownColor enumeration.
System.Array colorsArray = Enum.GetValues(typeof(KnownColor));
KnownColor[] allColors = new KnownColor[colorsArray.Length];
Array.Copy(colorsArray, allColors, colorsArray.Length);
// Loop through printing out the values' names in the colors
// they represent.
float y = 0;
float x = 10.0F;
SolidBrush bBrush = new SolidBrush(Color.Black);
Pen p1 = new Pen(Color.Black);
for (int i = 0; i < allColors.Length; i++)
{
// If x is a multiple of 45, start a new column.
if (i > 0 && i % 45 == 0)
{
x += 130.0F;
y = 15.0F;
}
else
{
// Otherwise, increment y by 15.
y += 15.0F;
}
// Create a custom brush from the color and use it to draw
// the brush's name.
SolidBrush aBrush = new SolidBrush(Color.FromName(allColors[i].ToString()));
e.Graphics.DrawRectangle(p1, x, y, 13.0F, 13.0F);
e.Graphics.FillRectangle(aBrush, x + 1.0F, y + 1.0F, 12.0F, 12.0F);
e.Graphics.DrawString(allColors[i].ToString(), this.Font, bBrush, x + 14.0F, y);
// Dispose of the custom brush.
aBrush.Dispose();
}
bBrush.Dispose();
p1.Dispose();
}
- 6/1/2011
- JoeBarrett