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
Gets the red component of this Color structure.
G
Gets the green component of this Color structure.
B
Gets the blue component of this Color structure.
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
FromArgb(int red, int green, int blue)
Creates a Color structure from the specified 8-bit color values.
FromArgb(int alpha, int red, int green, int blue)
Creates a Color structure from the specified 8-bit color values.
FromArgb(int argb)
Creates a Color structure from a 32-bit ARGB value.
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.AliceBlueColor.AntiqueWhiteColor.AquaColor.AquamarineColor.AzureColor.BlackColor.BlueColor.BlueVioletColor.BrownColor.BurlyWoodColor.CadetBlueColor.ChartreuseColor.ChocolateColor.CoralColor.CornflowerBlueColor.CornsilkColor.CrimsonColor.CyanColor.DarkBlueColor.DarkCyanColor.DarkGoldenrodColor.DarkGrayColor.DarkGreenColor.DarkKhakiColor.DarkMagentaColor.DarkOliveGreenColor.DarkOrangeColor.DarkOrchidColor.DarkRedColor.DarkSalmonColor.DarkSeaGreenColor.DarkSlateBlueColor.DarkSlateGrayColor.DarkTurquoiseColor.DarkVioletColor.DeepPinkColor.DeepSkyBlueColor.DimGrayColor.DodgerBlueColor.EmptyColor.FirebrickColor.FloralWhiteColor.ForestGreenColor.FuchsiaColor.GainsboroColor.GhostWhiteColor.GoldColor.GoldenrodColor.GrayColor.GreenColor.GreenYellowColor.HoneydewColor.HotPinkColor.IndianRedColor.IndigoColor.InvisibleColor.IvoryColor.KhakiColor.LavenderColor.LavenderBlushColor.LawnGreenColor.LemonChiffonColor.LightBlueColor.LightCoralColor.LightCyanColor.LightGoldenrodYellowColor.LightGrayColor.LightGreenColor.LightPinkColor.LightSalmonColor.LightSeaGreenColor.LightSkyBlueColor.LightSlateGrayColor.LightSteelBlueColor.LightYellowColor.LimeColor.LimeGreenColor.LinenColor.MagentaColor.MaroonColor.MediumAquamarineColor.MediumBlueColor.MediumOrchidColor.MediumPurpleColor.MediumSeaGreenColor.MediumSlateBlueColor.MediumSpringGreenColor.MediumTurquoiseColor.MediumVioletRedColor.MidnightBlueColor.MintCreamColor.MistyRoseColor.MoccasinColor.NavajoWhiteColor.NavyColor.OldLaceColor.OliveColor.OliveDrabColor.OrangeColor.OrangeRedColor.OrchidColor.PaleGoldenrodColor.PaleGreenColor.PaleTurquoiseColor.PaleVioletRedColor.PapayaWhipColor.PeachPuffColor.PeruColor.PinkColor.PlumColor.PowderBlueColor.PurpleColor.RedColor.RosyBrownColor.RoyalBlueColor.SaddleBrownColor.SalmonColor.SandyBrownColor.SeaGreenColor.SeaShellColor.SiennaColor.SilverColor.SkyBlueColor.SlateBlueColor.SlateGrayColor.SnowColor.SpringGreenColor.SteelBlueColor.TanColor.TealColor.ThistleColor.TomatoColor.TransparentColor.TurquoiseColor.VioletColor.WheatColor.WhiteColor.WhiteSmokeColor.YellowColor.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}");