Color Struct
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents an ARGB (alpha, red, green, blue) color.
public value class Color : IEquatable<System::Drawing::Color>
public value class Color
[System.ComponentModel.TypeConverter("System.Drawing.ColorConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public readonly struct Color : IEquatable<System.Drawing.Color>
public struct Color : IEquatable<System.Drawing.Color>
public readonly struct Color : IEquatable<System.Drawing.Color>
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ColorConverter))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Color
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ColorConverter))]
[System.Serializable]
public struct Color
public struct Color
[<System.ComponentModel.TypeConverter("System.Drawing.ColorConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type Color = struct
type Color = struct
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.ColorConverter))>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type Color = struct
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.ColorConverter))>]
[<System.Serializable>]
type Color = struct
Public Structure Color
Implements IEquatable(Of Color)
Public Structure Color
- Inheritance
- Attributes
- Implements
Examples
The following code example demonstrates the A, R, G, and B properties of a Color, and the Implicit member.
This example is designed to be used with a Windows Form. Paste the code into the form and call the ShowPropertiesOfSlateBlue
method from the form's Paint event-handling method, passing e
as PaintEventArgs.
void ShowPropertiesOfSlateBlue( PaintEventArgs^ e )
{
Color slateBlue = Color::FromName( "SlateBlue" );
Byte g = slateBlue.G;
Byte b = slateBlue.B;
Byte r = slateBlue.R;
Byte a = slateBlue.A;
array<Object^>^temp0 = {a,r,g,b};
String^ text = String::Format( "Slate Blue has these ARGB values: Alpha:{0}, "
"red:{1}, green: {2}, blue {3}", temp0 );
e->Graphics->DrawString( text, gcnew System::Drawing::Font( this->Font,FontStyle::Italic ), gcnew SolidBrush( slateBlue ), RectangleF(PointF(0.0F,0.0F),this->Size) );
}
private void ShowPropertiesOfSlateBlue(PaintEventArgs e)
{
Color slateBlue = Color.FromName("SlateBlue");
byte g = slateBlue.G;
byte b = slateBlue.B;
byte r = slateBlue.R;
byte a = slateBlue.A;
string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " +
"red:{1}, green: {2}, blue {3}", new object[]{a, r, g, b});
e.Graphics.DrawString(text,
new Font(this.Font, FontStyle.Italic),
new SolidBrush(slateBlue),
new RectangleF(new PointF(0.0F, 0.0F), this.Size));
}
Private Sub ShowPropertiesOfSlateBlue(ByVal e As PaintEventArgs)
Dim slateBlue As Color = Color.FromName("SlateBlue")
Dim g As Byte = slateBlue.G
Dim b As Byte = slateBlue.B
Dim r As Byte = slateBlue.R
Dim a As Byte = slateBlue.A
Dim text As String = _
String.Format("Slate Blue has these ARGB values: Alpha:{0}, " _
& "red:{1}, green: {2}, blue {3}", New Object() {a, r, g, b})
e.Graphics.DrawString(text, New Font(Me.Font, FontStyle.Italic), _
New SolidBrush(slateBlue), _
New RectangleF(New PointF(0.0F, 0.0F), _
Size.op_Implicit(Me.Size)))
End Sub
Remarks
Named colors are represented by using the properties of the Color structure.
The color of each pixel is represented as a 32-bit number: 8 bits each for alpha, red, green, and blue (ARGB). Each of the four components is a number from 0 through 255, with 0 representing no intensity and 255 representing full intensity. The alpha component specifies the transparency of the color: 0 is fully transparent, and 255 is fully opaque. To determine the alpha, red, green, or blue component of a color, use the A, R, G, or B property, respectively. You can create a custom color by using one of the FromArgb methods.
For more information about these colors, see List of colors by name.
Fields
Empty |
Represents a color that is |
Properties
A |
Gets the alpha component value of this Color structure. |
AliceBlue |
Gets a system-defined color that has an ARGB value of |
AntiqueWhite |
Gets a system-defined color that has an ARGB value of |
Aqua |
Gets a system-defined color that has an ARGB value of |
Aquamarine |
Gets a system-defined color that has an ARGB value of |
Azure |
Gets a system-defined color that has an ARGB value of |
B |
Gets the blue component value of this Color structure. |
Beige |
Gets a system-defined color that has an ARGB value of |
Bisque |
Gets a system-defined color that has an ARGB value of |
Black |
Gets a system-defined color that has an ARGB value of |
BlanchedAlmond |
Gets a system-defined color that has an ARGB value of |
Blue |
Gets a system-defined color that has an ARGB value of |
BlueViolet |
Gets a system-defined color that has an ARGB value of |
Brown |
Gets a system-defined color that has an ARGB value of |
BurlyWood |
Gets a system-defined color that has an ARGB value of |
CadetBlue |
Gets a system-defined color that has an ARGB value of |
Chartreuse |
Gets a system-defined color that has an ARGB value of |
Chocolate |
Gets a system-defined color that has an ARGB value of |
Coral |
Gets a system-defined color that has an ARGB value of |
CornflowerBlue |
Gets a system-defined color that has an ARGB value of |
Cornsilk |
Gets a system-defined color that has an ARGB value of |
Crimson |
Gets a system-defined color that has an ARGB value of |
Cyan |
Gets a system-defined color that has an ARGB value of |
DarkBlue |
Gets a system-defined color that has an ARGB value of |
DarkCyan |
Gets a system-defined color that has an ARGB value of |
DarkGoldenrod |
Gets a system-defined color that has an ARGB value of |
DarkGray |
Gets a system-defined color that has an ARGB value of |
DarkGreen |
Gets a system-defined color that has an ARGB value of |
DarkKhaki |
Gets a system-defined color that has an ARGB value of |
DarkMagenta |
Gets a system-defined color that has an ARGB value of |
DarkOliveGreen |
Gets a system-defined color that has an ARGB value of |
DarkOrange |
Gets a system-defined color that has an ARGB value of |
DarkOrchid |
Gets a system-defined color that has an ARGB value of |
DarkRed |
Gets a system-defined color that has an ARGB value of |
DarkSalmon |
Gets a system-defined color that has an ARGB value of |
DarkSeaGreen |
Gets a system-defined color that has an ARGB value of |
DarkSlateBlue |
Gets a system-defined color that has an ARGB value of |
DarkSlateGray |
Gets a system-defined color that has an ARGB value of |
DarkTurquoise |
Gets a system-defined color that has an ARGB value of |
DarkViolet |
Gets a system-defined color that has an ARGB value of |
DeepPink |
Gets a system-defined color that has an ARGB value of |
DeepSkyBlue |
Gets a system-defined color that has an ARGB value of |
DimGray |
Gets a system-defined color that has an ARGB value of |
DodgerBlue |
Gets a system-defined color that has an ARGB value of |
Firebrick |
Gets a system-defined color that has an ARGB value of |
FloralWhite |
Gets a system-defined color that has an ARGB value of |
ForestGreen |
Gets a system-defined color that has an ARGB value of |
Fuchsia |
Gets a system-defined color that has an ARGB value of |
G |
Gets the green component value of this Color structure. |
Gainsboro |
Gets a system-defined color that has an ARGB value of |
GhostWhite |
Gets a system-defined color that has an ARGB value of |
Gold |
Gets a system-defined color that has an ARGB value of |
Goldenrod |
Gets a system-defined color that has an ARGB value of |
Gray |
Gets a system-defined color that has an ARGB value of |
Green |
Gets a system-defined color that has an ARGB value of |
GreenYellow |
Gets a system-defined color that has an ARGB value of |
Honeydew |
Gets a system-defined color that has an ARGB value of |
HotPink |
Gets a system-defined color that has an ARGB value of |
IndianRed |
Gets a system-defined color that has an ARGB value of |
Indigo |
Gets a system-defined color that has an ARGB value of |
IsEmpty |
Specifies whether this Color structure is uninitialized. |
IsKnownColor |
Gets a value indicating whether this Color structure is a predefined color. Predefined colors are represented by the elements of the KnownColor enumeration. |
IsNamedColor |
Gets a value indicating whether this Color structure is a named color or a member of the KnownColor enumeration. |
IsSystemColor |
Gets a value indicating whether this Color structure is a system color. A system color is a color that is used in a Windows display element. System colors are represented by elements of the KnownColor enumeration. |
Ivory |
Gets a system-defined color that has an ARGB value of |
Khaki |
Gets a system-defined color that has an ARGB value of |
Lavender |
Gets a system-defined color that has an ARGB value of |
LavenderBlush |
Gets a system-defined color that has an ARGB value of |
LawnGreen |
Gets a system-defined color that has an ARGB value of |
LemonChiffon |
Gets a system-defined color that has an ARGB value of |
LightBlue |
Gets a system-defined color that has an ARGB value of |
LightCoral |
Gets a system-defined color that has an ARGB value of |
LightCyan |
Gets a system-defined color that has an ARGB value of |
LightGoldenrodYellow |
Gets a system-defined color that has an ARGB value of |
LightGray |
Gets a system-defined color that has an ARGB value of |
LightGreen |
Gets a system-defined color that has an ARGB value of |
LightPink |
Gets a system-defined color that has an ARGB value of |
LightSalmon |
Gets a system-defined color that has an ARGB value of |
LightSeaGreen |
Gets a system-defined color that has an ARGB value of |
LightSkyBlue |
Gets a system-defined color that has an ARGB value of |
LightSlateGray |
Gets a system-defined color that has an ARGB value of |
LightSteelBlue |
Gets a system-defined color that has an ARGB value of |
LightYellow |
Gets a system-defined color that has an ARGB value of |
Lime |
Gets a system-defined color that has an ARGB value of |
LimeGreen |
Gets a system-defined color that has an ARGB value of |
Linen |
Gets a system-defined color that has an ARGB value of |
Magenta |
Gets a system-defined color that has an ARGB value of |
Maroon |
Gets a system-defined color that has an ARGB value of |
MediumAquamarine |
Gets a system-defined color that has an ARGB value of |
MediumBlue |
Gets a system-defined color that has an ARGB value of |
MediumOrchid |
Gets a system-defined color that has an ARGB value of |
MediumPurple |
Gets a system-defined color that has an ARGB value of |
MediumSeaGreen |
Gets a system-defined color that has an ARGB value of |
MediumSlateBlue |
Gets a system-defined color that has an ARGB value of |
MediumSpringGreen |
Gets a system-defined color that has an ARGB value of |
MediumTurquoise |
Gets a system-defined color that has an ARGB value of |
MediumVioletRed |
Gets a system-defined color that has an ARGB value of |
MidnightBlue |
Gets a system-defined color that has an ARGB value of |
MintCream |
Gets a system-defined color that has an ARGB value of |
MistyRose |
Gets a system-defined color that has an ARGB value of |
Moccasin |
Gets a system-defined color that has an ARGB value of |
Name |
Gets the name of this Color. |
NavajoWhite |
Gets a system-defined color that has an ARGB value of |
Navy |
Gets a system-defined color that has an ARGB value of |
OldLace |
Gets a system-defined color that has an ARGB value of |
Olive |
Gets a system-defined color that has an ARGB value of |
OliveDrab |
Gets a system-defined color that has an ARGB value of |
Orange |
Gets a system-defined color that has an ARGB value of |
OrangeRed |
Gets a system-defined color that has an ARGB value of |
Orchid |
Gets a system-defined color that has an ARGB value of |
PaleGoldenrod |
Gets a system-defined color that has an ARGB value of |
PaleGreen |
Gets a system-defined color that has an ARGB value of |
PaleTurquoise |
Gets a system-defined color that has an ARGB value of |
PaleVioletRed |
Gets a system-defined color that has an ARGB value of |
PapayaWhip |
Gets a system-defined color that has an ARGB value of |
PeachPuff |
Gets a system-defined color that has an ARGB value of |
Peru |
Gets a system-defined color that has an ARGB value of |
Pink |
Gets a system-defined color that has an ARGB value of |
Plum |
Gets a system-defined color that has an ARGB value of |
PowderBlue |
Gets a system-defined color that has an ARGB value of |
Purple |
Gets a system-defined color that has an ARGB value of |
R |
Gets the red component value of this Color structure. |
RebeccaPurple |
Gets a system-defined color that has an ARGB value of |
Red |
Gets a system-defined color that has an ARGB value of |
RosyBrown |
Gets a system-defined color that has an ARGB value of |
RoyalBlue |
Gets a system-defined color that has an ARGB value of |
SaddleBrown |
Gets a system-defined color that has an ARGB value of |
Salmon |
Gets a system-defined color that has an ARGB value of |
SandyBrown |
Gets a system-defined color that has an ARGB value of |
SeaGreen |
Gets a system-defined color that has an ARGB value of |
SeaShell |
Gets a system-defined color that has an ARGB value of |
Sienna |
Gets a system-defined color that has an ARGB value of |
Silver |
Gets a system-defined color that has an ARGB value of |
SkyBlue |
Gets a system-defined color that has an ARGB value of |
SlateBlue |
Gets a system-defined color that has an ARGB value of |
SlateGray |
Gets a system-defined color that has an ARGB value of |
Snow |
Gets a system-defined color that has an ARGB value of |
SpringGreen |
Gets a system-defined color that has an ARGB value of |
SteelBlue |
Gets a system-defined color that has an ARGB value of |
Tan |
Gets a system-defined color that has an ARGB value of |
Teal |
Gets a system-defined color that has an ARGB value of |
Thistle |
Gets a system-defined color that has an ARGB value of |
Tomato |
Gets a system-defined color that has an ARGB value of |
Transparent |
Gets a system-defined color. |
Turquoise |
Gets a system-defined color that has an ARGB value of |
Violet |
Gets a system-defined color that has an ARGB value of |
Wheat |
Gets a system-defined color that has an ARGB value of |
White |
Gets a system-defined color that has an ARGB value of |
WhiteSmoke |
Gets a system-defined color that has an ARGB value of |
Yellow |
Gets a system-defined color that has an ARGB value of |
YellowGreen |
Gets a system-defined color that has an ARGB value of |
Methods
Equals(Color) |
Indicates whether the current object is equal to another object of the same type. |
Equals(Object) |
Tests whether the specified object is a Color structure and is equivalent to this Color structure. |
FromArgb(Int32, Color) |
Creates a Color structure from the specified Color structure, but with the new specified alpha value. Although this method allows a 32-bit value to be passed for the alpha value, the value is limited to 8 bits. |
FromArgb(Int32, Int32, Int32, Int32) |
Creates a Color structure from the four ARGB component (alpha, red, green, and blue) values. Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits. |
FromArgb(Int32, Int32, Int32) |
Creates a Color structure from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits. |
FromArgb(Int32) |
Creates a Color structure from a 32-bit ARGB value. |
FromKnownColor(KnownColor) |
Creates a Color structure from the specified predefined color. |
FromName(String) |
Creates a Color structure from the specified name of a predefined color. |
GetBrightness() |
Gets the hue-saturation-lightness (HSL) lightness value for this Color structure. |
GetHashCode() |
Returns a hash code for this Color structure. |
GetHue() |
Gets the hue-saturation-lightness (HSL) hue value, in degrees, for this Color structure. |
GetSaturation() |
Gets the hue-saturation-lightness (HSL) saturation value for this Color structure. |
ToArgb() |
Gets the 32-bit ARGB value of this Color structure. |
ToKnownColor() |
Gets the KnownColor value of this Color structure. |
ToString() |
Converts this Color structure to a human-readable string. |
Operators
Equality(Color, Color) |
Tests whether two specified Color structures are equivalent. |
Inequality(Color, Color) |
Tests whether two specified Color structures are different. |