The Color structure is a value type that represents a point in the RGB color space, with optional support for a transparency alpha channel.

You can obtain the value of a particular Color by using one of the static properties that return a well-known web color. Alternatively, FromArgb() allows you to define a specific color from its red, green, blue, and alpha components. FromKnownColor() allows you to create a Color from an entry in KnownColor enumeration, and FromName() takes a string containing the name of well-known color.

There is also a special field, Empty, which represents a null color. This is necessary because Color is a value type, and therefore nullness cannot be represented by a null reference. It is usually used when a class can optionally inherit its color from an ambient property (e.g., the ForeColor of a Control is inherited from its Parent if set to Empty). The IsEmpty property allows you to check for nullness.

There are properties that allow you to retrieve the A, R, G, and B values of the color, and the color’s Name (either the well-known name or a string description of the ARGB values as appropriate). In addition, there are methods—GetHue(), GetSaturation(), and GetBrightness()—to transform the values to the HSB color space.

If you need to know whether a color is well-known, you can use the IsKnownColor, IsNamedColor, and IsSystemColor properties.

The Color structure is used pervasively throughout the framework wherever color is needed.

 public struct ...

Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.