The Color structure represents an RGBA (red, green, blue, alpha) color.

Overview

The System.Drawing.Color structure is a fundamental part of the System.Drawing namespace, providing a way to represent, manipulate, and use colors in graphics applications. Each color is defined by its red, green, blue, and alpha components. The alpha component controls the opacity of the color, with 0 being fully transparent and 255 being fully opaque.

Properties

R

R

Gets the red component of this Color structure.

G

G

Gets the green component of this Color structure.

B

B

Gets the blue component of this Color structure.

A

A

Gets the alpha component of this Color structure.

#

ToArgb()

Converts this Color structure to a 32-bit ARGB (alpha, red, green, blue) value.

#

IsKnownColor

Gets a value indicating whether this Color structure is a predefined color or system color.

#

IsNamedColor

Gets a value indicating whether this Color structure is an identifiable color.

Methods

C

FromArgb(int red, int green, int blue)

Creates a Color structure from the specified 8-bit color values.

C

FromArgb(int alpha, int red, int green, int blue)

Creates a Color structure from the specified 8-bit color values.

C

FromArgb(int argb)

Creates a Color structure from a 32-bit ARGB value.

C

FromName(string name)

Creates a Color structure from the specified name of a predefined or system color.

Static Properties

The Color class provides a large collection of static properties representing common colors.

  • Color.AliceBlue
  • Color.AntiqueWhite
  • Color.Aqua
  • Color.Aquamarine
  • Color.Azure
  • Color.Black
  • Color.Blue
  • Color.BlueViolet
  • Color.Brown
  • Color.BurlyWood
  • Color.CadetBlue
  • Color.Chartreuse
  • Color.Chocolate
  • Color.Coral
  • Color.CornflowerBlue
  • Color.Cornsilk
  • Color.Crimson
  • Color.Cyan
  • Color.DarkBlue
  • Color.DarkCyan
  • Color.DarkGoldenrod
  • Color.DarkGray
  • Color.DarkGreen
  • Color.DarkKhaki
  • Color.DarkMagenta
  • Color.DarkOliveGreen
  • Color.DarkOrange
  • Color.DarkOrchid
  • Color.DarkRed
  • Color.DarkSalmon
  • Color.DarkSeaGreen
  • Color.DarkSlateBlue
  • Color.DarkSlateGray
  • Color.DarkTurquoise
  • Color.DarkViolet
  • Color.DeepPink
  • Color.DeepSkyBlue
  • Color.DimGray
  • Color.DodgerBlue
  • Color.Empty
  • Color.Firebrick
  • Color.FloralWhite
  • Color.ForestGreen
  • Color.Fuchsia
  • Color.Gainsboro
  • Color.GhostWhite
  • Color.Gold
  • Color.Goldenrod
  • Color.Gray
  • Color.Green
  • Color.GreenYellow
  • Color.Honeydew
  • Color.HotPink
  • Color.IndianRed
  • Color.Indigo
  • Color.Invisible
  • Color.Ivory
  • Color.Khaki
  • Color.Lavender
  • Color.LavenderBlush
  • Color.LawnGreen
  • Color.LemonChiffon
  • Color.LightBlue
  • Color.LightCoral
  • Color.LightCyan
  • Color.LightGoldenrodYellow
  • Color.LightGray
  • Color.LightGreen
  • Color.LightPink
  • Color.LightSalmon
  • Color.LightSeaGreen
  • Color.LightSkyBlue
  • Color.LightSlateGray
  • Color.LightSteelBlue
  • Color.LightYellow
  • Color.Lime
  • Color.LimeGreen
  • Color.Linen
  • Color.Magenta
  • Color.Maroon
  • Color.MediumAquamarine
  • Color.MediumBlue
  • Color.MediumOrchid
  • Color.MediumPurple
  • Color.MediumSeaGreen
  • Color.MediumSlateBlue
  • Color.MediumSpringGreen
  • Color.MediumTurquoise
  • Color.MediumVioletRed
  • Color.MidnightBlue
  • Color.MintCream
  • Color.MistyRose
  • Color.Moccasin
  • Color.NavajoWhite
  • Color.Navy
  • Color.OldLace
  • Color.Olive
  • Color.OliveDrab
  • Color.Orange
  • Color.OrangeRed
  • Color.Orchid
  • Color.PaleGoldenrod
  • Color.PaleGreen
  • Color.PaleTurquoise
  • Color.PaleVioletRed
  • Color.PapayaWhip
  • Color.PeachPuff
  • Color.Peru
  • Color.Pink
  • Color.Plum
  • Color.PowderBlue
  • Color.Purple
  • Color.Red
  • Color.RosyBrown
  • Color.RoyalBlue
  • Color.SaddleBrown
  • Color.Salmon
  • Color.SandyBrown
  • Color.SeaGreen
  • Color.SeaShell
  • Color.Sienna
  • Color.Silver
  • Color.SkyBlue
  • Color.SlateBlue
  • Color.SlateGray
  • Color.Snow
  • Color.SpringGreen
  • Color.SteelBlue
  • Color.Tan
  • Color.Teal
  • Color.Thistle
  • Color.Tomato
  • Color.Transparent
  • Color.Turquoise
  • Color.Violet
  • Color.Wheat
  • Color.White
  • Color.WhiteSmoke
  • Color.Yellow
  • Color.YellowGreen

Example Usage

Creating a color from ARGB values


using System.Drawing;

// Create a semi-transparent red color
Color semiTransparentRed = Color.FromArgb(128, 255, 0, 0);

// Create an opaque green color
Color opaqueGreen = Color.FromArgb(0, 0, 255, 0);
                    

Creating a color from a predefined name


using System.Drawing;

Color skyBlue = Color.FromName("SkyBlue");
Color aliceBlue = Color.AliceBlue; // Using static property
                    

Accessing color components


using System.Drawing;

Color myColor = Color.FromArgb(255, 100, 150, 200); // Opaque, R=100, G=150, B=200

int redComponent = myColor.R;
int greenComponent = myColor.G;
int blueComponent = myColor.B;
int alphaComponent = myColor.A;

Console.WriteLine($"Red: {redComponent}, Green: {greenComponent}, Blue: {blueComponent}, Alpha: {alphaComponent}");
// Output: Red: 100, Green: 150, Blue: 200, Alpha: 255
                    

Converting to ARGB value


using System.Drawing;

Color orange = Color.Orange;
int argbValue = orange.ToArgb();

Console.WriteLine($"ARGB value for Orange: {argbValue}");