Color 结构
定义
表示一种 ARGB 颜色(alpha、红色、绿色、蓝色)。Represents an ARGB (alpha, red, green, blue) color.
public value class Color : IEquatable<System::Drawing::Color>
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ColorConverter))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Color : IEquatable<System.Drawing.Color>
type Color = struct
Public Structure Color
Implements IEquatable(Of Color)
- 继承
- 属性
- 实现
示例
下面的代码示例演示了 Color 和 Implicit 成员的 A、R G 和 B 属性。The following code example demonstrates the A, R, G, and B properties of a Color, and the Implicit member.
此示例旨在与 Windows 窗体一起使用。This example is designed to be used with a Windows Form. 将代码粘贴到窗体中,并从窗体的 Paint 事件处理方法中调用 ShowPropertiesOfSlateBlue
方法,并将 e
作为 PaintEventArgs。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
注解
命名颜色通过使用 Color 结构的属性来表示。Named colors are represented by using the properties of the Color structure. 有关这些颜色的详细信息,请参阅按名称显示颜色。For more information about these colors, see Colors by Name.
每个像素的颜色表示为32位数字:8位,分别用于 alpha、红色、绿色和蓝色(ARGB)。The color of each pixel is represented as a 32-bit number: 8 bits each for alpha, red, green, and blue (ARGB). 这四个组件都是0到255之间的一个数字,0表示没有强度,255表示完全强度。Each of the four components is a number from 0 through 255, with 0 representing no intensity and 255 representing full intensity. Alpha 分量指定颜色的透明度:0完全透明,255完全不透明。The alpha component specifies the transparency of the color: 0 is fully transparent, and 255 is fully opaque. 若要确定颜色的 alpha、红色、绿色或蓝色分量,请分别使用 A、R、G 或 B 属性。To determine the alpha, red, green, or blue component of a color, use the A, R, G, or B property, respectively. 您可以使用 FromArgb 方法之一创建自定义颜色。You can create a custom color by using one of the FromArgb methods.
字段
Empty |
表示值为 |
属性
A |
获取此 Color 结构的 alpha 组件值。Gets the alpha component value of this Color structure. |
AliceBlue |
获取 ARGB 值为 #FFF0F8FF 的系统定义的颜色 |
AntiqueWhite |
获取 ARGB 值为 #FFFAEBD7 的系统定义的颜色 |
Aqua |
获取 ARGB 值为 #FF00FFFF 的系统定义的颜色 |
Aquamarine |
获取 ARGB 值为 #FF7FFFD4 的系统定义的颜色 |
Azure |
获取 ARGB 值为 #FFF0FFFF 的系统定义的颜色 |
B |
获取此 Color 结构的蓝色组件值。Gets the blue component value of this Color structure. |
Beige |
获取 ARGB 值为 #FFF5F5DC 的系统定义的颜色 |
Bisque |
获取 ARGB 值为 #FFFFE4C4 的系统定义的颜色 |
Black |
获取 ARGB 值为 #FF000000 的系统定义的颜色 |
BlanchedAlmond |
获取 ARGB 值为 #FFFFEBCD 的系统定义的颜色 |
Blue |
获取 ARGB 值为 #FF0000FF 的系统定义的颜色 |
BlueViolet |
获取 ARGB 值为 #FF8A2BE2 的系统定义的颜色 |
Brown |
获取 ARGB 值为 #FFA52A2A 的系统定义的颜色 |
BurlyWood |
获取 ARGB 值为 #FFDEB887 的系统定义的颜色 |
CadetBlue |
获取 ARGB 值为 #FF5F9EA0 的系统定义的颜色 |
Chartreuse |
获取 ARGB 值为 #FF7FFF00 的系统定义的颜色 |
Chocolate |
获取 ARGB 值为 #FFD2691E 的系统定义的颜色 |
Coral |
获取 ARGB 值为 #FFFF7F50 的系统定义的颜色 |
CornflowerBlue |
获取 ARGB 值为 #FF6495ED 的系统定义的颜色 |
Cornsilk |
获取 ARGB 值为 #FFFFF8DC 的系统定义的颜色 |
Crimson |
获取 ARGB 值为 #FFDC143C 的系统定义的颜色 |
Cyan |
获取 ARGB 值为 #FF00FFFF 的系统定义的颜色 |
DarkBlue |
获取 ARGB 值为 #FF00008B 的系统定义的颜色 |
DarkCyan |
获取 ARGB 值为 #FF008B8B 的系统定义的颜色 |
DarkGoldenrod |
获取 ARGB 值为 #FFB8860B 的系统定义的颜色 |
DarkGray |
获取 ARGB 值为 #FFA9A9A9 的系统定义的颜色 |
DarkGreen |
获取 ARGB 值为 #FF006400 的系统定义的颜色 |
DarkKhaki |
获取 ARGB 值为 #FFBDB76B 的系统定义的颜色 |
DarkMagenta |
获取 ARGB 值为 #FF8B008B 的系统定义的颜色 |
DarkOliveGreen |
获取 ARGB 值为 #FF556B2F 的系统定义的颜色 |
DarkOrange |
获取 ARGB 值为 #FFFF8C00 的系统定义的颜色 |
DarkOrchid |
获取 ARGB 值为 #FF9932CC 的系统定义的颜色 |
DarkRed |
获取 ARGB 值为 #FF8B0000 的系统定义的颜色 |
DarkSalmon |
获取 ARGB 值为 #FFE9967A 的系统定义的颜色 |
DarkSeaGreen |
获取 ARGB 值为 |
DarkSlateBlue |
获取 ARGB 值为 #FF483D8B 的系统定义的颜色 |
DarkSlateGray |
获取 ARGB 值为 #FF2F4F4F 的系统定义的颜色 |
DarkTurquoise |
获取 ARGB 值为 #FF00CED1 的系统定义的颜色 |
DarkViolet |
获取 ARGB 值为 #FF9400D3 的系统定义的颜色 |
DeepPink |
获取 ARGB 值为 #FFFF1493 的系统定义的颜色 |
DeepSkyBlue |
获取 ARGB 值为 #FF00BFFF 的系统定义的颜色 |
DimGray |
获取 ARGB 值为 #FF696969 的系统定义的颜色 |
DodgerBlue |
获取 ARGB 值为 #FF1E90FF 的系统定义的颜色 |
Firebrick |
获取 ARGB 值为 #FFB22222 的系统定义的颜色 |
FloralWhite |
获取 ARGB 值为 #FFFFFAF0 的系统定义的颜色 |
ForestGreen |
获取 ARGB 值为 #FF228B22 的系统定义的颜色 |
Fuchsia |
获取 ARGB 值为 #FFFF00FF 的系统定义颜色 |
G |
获取此 Color 结构的绿色组件值。Gets the green component value of this Color structure. |
Gainsboro |
获取 ARGB 值为 #FFDCDCDC 的系统定义颜色 |
GhostWhite |
获取 ARGB 值为 #FFF8F8FF 的系统定义颜色 |
Gold |
获取 ARGB 值为 #FFFFD700 的系统定义颜色 |
Goldenrod |
获取 ARGB 值为 #FFDAA520 的系统定义颜色 |
Gray |
获取 ARGB 值为 #FF808080 的系统定义颜色 |
Green |
获取 ARGB 值为 #FF008000 的系统定义颜色 |
GreenYellow |
获取 ARGB 值为 #FFADFF2F 的系统定义颜色 |
Honeydew |
获取 ARGB 值为 #FFF0FFF0 的系统定义颜色 |
HotPink |
获取 ARGB 值为 #FFFF69B4 的系统定义颜色 |
IndianRed |
获取 ARGB 值为 #FFCD5C5C 的系统定义颜色 |
Indigo |
获取 ARGB 值为 #FF4B0082 的系统定义颜色 |
IsEmpty |
指定是否取消初始化此 Color 结构。Specifies whether this Color structure is uninitialized. |
IsKnownColor |
获取指示此 Color 结构是否为预定义颜色的值。Gets a value indicating whether this Color structure is a predefined color. 预定义颜色由 KnownColor 枚举的元素表示。Predefined colors are represented by the elements of the KnownColor enumeration. |
IsNamedColor |
获取指示此 Color 结构是命名颜色还是 KnownColor 枚举成员的值。Gets a value indicating whether this Color structure is a named color or a member of the KnownColor enumeration. |
IsSystemColor |
获取指示此 Color 结构是否为系统颜色的值。Gets a value indicating whether this Color structure is a system color. 系统颜色是指 Windows 显示元素中使用的颜色。A system color is a color that is used in a Windows display element. 系统颜色由 KnownColor 枚举的元素来表示。System colors are represented by elements of the KnownColor enumeration. |
Ivory |
获取 ARGB 值为 #FFFFFFF0 的系统定义颜色 |
Khaki |
获取 ARGB 值为 #FFF0E68C 的系统定义颜色 |
Lavender |
获取 ARGB 值为 #FFE6E6FA 的系统定义颜色 |
LavenderBlush |
获取 ARGB 值为 #FFFFF0F5 的系统定义颜色 |
LawnGreen |
获取 ARGB 值为 #FF7CFC00 的系统定义颜色 |
LemonChiffon |
获取 ARGB 值为 #FFFFFACD 的系统定义颜色 |
LightBlue |
获取 ARGB 值为 #FFADD8E6 的系统定义颜色 |
LightCoral |
获取 ARGB 值为 #FFF08080 的系统定义颜色 |
LightCyan |
获取 ARGB 值为 #FFE0FFFF 的系统定义颜色 |
LightGoldenrodYellow |
获取 ARGB 值为 #FFFAFAD2 的系统定义颜色 |
LightGray |
获取 ARGB 值为 #FFD3D3D3 的系统定义颜色 |
LightGreen |
获取 ARGB 值为 #FF90EE90 的系统定义颜色 |
LightPink |
获取 ARGB 值为 #FFFFB6C1 的系统定义颜色 |
LightSalmon |
获取 ARGB 值为 #FFFFA07A 的系统定义颜色 |
LightSeaGreen |
获取 ARGB 值为 #FF20B2AA 的系统定义颜色 |
LightSkyBlue |
获取 ARGB 值为 #FF87CEFA 的系统定义颜色 |
LightSlateGray |
获取 ARGB 值为 #FF778899 的系统定义颜色 |
LightSteelBlue |
获取 ARGB 值为 #FFB0C4DE 的系统定义颜色 |
LightYellow |
获取 ARGB 值为 #FFFFFFE0 的系统定义颜色 |
Lime |
获取 ARGB 值为 #FF00FF00 的系统定义颜色 |
LimeGreen |
获取 ARGB 值为 #FF32CD32 的系统定义颜色 |
Linen |
获取 ARGB 值为 #FFFAF0E6 的系统定义颜色 |
Magenta |
获取 ARGB 值为 #FFFF00FF 的系统定义颜色 |
Maroon |
获取 ARGB 值为 #FF800000 的系统定义颜色 |
MediumAquamarine |
获取 ARGB 值为 #FF66CDAA 的系统定义颜色 |
MediumBlue |
获取 ARGB 值为 #FF0000CD 的系统定义颜色 |
MediumOrchid |
获取 ARGB 值为 #FFBA55D3 的系统定义颜色 |
MediumPurple |
获取 ARGB 值为 #FF9370DB 的系统定义颜色 |
MediumSeaGreen |
获取 ARGB 值为 #FF3CB371 的系统定义颜色 |
MediumSlateBlue |
获取 ARGB 值为 #FF7B68EE 的系统定义颜色 |
MediumSpringGreen |
获取 ARGB 值为 #FF00FA9A 的系统定义颜色 |
MediumTurquoise |
获取 ARGB 值为 #FF48D1CC 的系统定义颜色 |
MediumVioletRed |
获取 ARGB 值为 #FFC71585 的系统定义颜色 |
MidnightBlue |
获取 ARGB 值为 #FF191970 的系统定义颜色 |
MintCream |
获取 ARGB 值为 #FFF5FFFA 的系统定义颜色 |
MistyRose |
获取 ARGB 值为 #FFFFE4E1 的系统定义颜色 |
Moccasin |
获取 ARGB 值为 #FFFFE4B5 的系统定义颜色 |
Name | |
NavajoWhite |
获取 ARGB 值为 #FFFFDEAD 的系统定义颜色 |
Navy |
获取 ARGB 值为 #FF000080 的系统定义颜色 |
OldLace |
获取 ARGB 值为 #FFFDF5E6 的系统定义颜色 |
Olive |
获取 ARGB 值为 #FF808000 的系统定义颜色 |
OliveDrab |
获取 ARGB 值为 #FF6B8E23 的系统定义颜色 |
Orange |
获取 ARGB 值为 #FFFFA500 的系统定义颜色 |
OrangeRed |
获取 ARGB 值为 #FFFF4500 的系统定义颜色 |
Orchid |
获取 ARGB 值为 #FFDA70D6 的系统定义颜色 |
PaleGoldenrod |
获取 ARGB 值为 #FFEEE8AA 的系统定义颜色 |
PaleGreen |
获取 ARGB 值为 #FF98FB98 的系统定义颜色 |
PaleTurquoise |
获取 ARGB 值为 #FFAFEEEE 的系统定义颜色 |
PaleVioletRed |
获取 ARGB 值为 #FFDB7093 的系统定义颜色 |
PapayaWhip |
获取 ARGB 值为 #FFFFEFD5 的系统定义颜色 |
PeachPuff |
获取 ARGB 值为 #FFFFDAB9 的系统定义颜色 |
Peru |
获取 ARGB 值为 #FFCD853F 的系统定义颜色 |
Pink |
获取 ARGB 值为 #FFFFC0CB 的系统定义颜色 |
Plum |
获取 ARGB 值为 #FFDDA0DD 的系统定义颜色 |
PowderBlue |
获取 ARGB 值为 #FFB0E0E6 的系统定义颜色 |
Purple |
获取 ARGB 值为 #FF800080 的系统定义颜色 |
R |
获取此 Color 结构的红色组件值。Gets the red component value of this Color structure. |
Red |
获取 ARGB 值为 #FFFF0000 的系统定义颜色 |
RosyBrown |
获取 ARGB 值为 #FFBC8F8F 的系统定义颜色 |
RoyalBlue |
获取 ARGB 值为 #FF4169E1 的系统定义颜色 |
SaddleBrown |
获取 ARGB 值为 #FF8B4513 的系统定义颜色 |
Salmon |
获取 ARGB 值为 #FFFA8072 的系统定义颜色 |
SandyBrown |
获取 ARGB 值为 #FFF4A460 的系统定义颜色 |
SeaGreen |
获取 ARGB 值为 #FF2E8B57 的系统定义颜色 |
SeaShell |
获取 ARGB 值为 #FFFFF5EE 的系统定义颜色 |
Sienna |
获取 ARGB 值为 #FFA0522D 的系统定义颜色 |
Silver |
获取 ARGB 值为 #FFC0C0C0 的系统定义颜色 |
SkyBlue |
获取 ARGB 值为 #FF87CEEB 的系统定义颜色 |
SlateBlue |
获取 ARGB 值为 #FF6A5ACD 的系统定义颜色 |
SlateGray |
获取 ARGB 值为 #FF708090 的系统定义颜色 |
Snow |
获取 ARGB 值为 #FFFFFAFA 的系统定义颜色 |
SpringGreen |
获取 ARGB 值为 #FF00FF7F 的系统定义颜色 |
SteelBlue |
获取 ARGB 值为 #FF4682B4 的系统定义颜色 |
Tan |
获取 ARGB 值为 #FFD2B48C 的系统定义颜色 |
Teal |
获取 ARGB 值为 #FF008080 的系统定义颜色 |
Thistle |
获取 ARGB 值为 #FFD8BFD8 的系统定义颜色 |
Tomato |
获取 ARGB 值为 #FFFF6347 的系统定义颜色 |
Transparent |
获取系统定义的颜色。Gets a system-defined color. |
Turquoise |
获取 ARGB 值为 #FF40E0D0 的系统定义颜色 |
Violet |
获取 ARGB 值为 #FFEE82EE 的系统定义颜色 |
Wheat |
获取 ARGB 值为 #FFF5DEB3 的系统定义颜色 |
White |
获取 ARGB 值为 #FFFFFFFF 的系统定义颜色 |
WhiteSmoke |
获取 ARGB 值为 #FFF5F5F5 的系统定义颜色 |
Yellow |
获取 ARGB 值为 #FFFFFF00 的系统定义颜色 |
YellowGreen |
获取 ARGB 值为 #FF9ACD32 的系统定义颜色 |
方法
Equals(Color) | |
Equals(Object) |
测试指定的对象是否为 Color 结构并等效于此 Color 结构。Tests whether the specified object is a Color structure and is equivalent to this Color structure. |
FromArgb(Int32) |
基于一个 32 位 ARGB 值创建 Color 结构。Creates a Color structure from a 32-bit ARGB value. |
FromArgb(Int32, Color) |
从指定的 Color 结构创建 Color 结构,但要使用新指定的 alpha 值。Creates a Color structure from the specified Color structure, but with the new specified alpha value. 尽管此方法允许为 alpha 值传递 32 位值,但该值仅限于 8 位。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) |
基于指定的 8 位颜色值(红色、绿色和蓝色)创建 Color 结构。Creates a Color structure from the specified 8-bit color values (red, green, and blue). 隐式的 alpha 值为 255(完全不透明)。The alpha value is implicitly 255 (fully opaque). 尽管此方法允许为每个颜色组件传递 32 位值,但每个组件的值仅限于 8 位。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, Int32, Int32, Int32) |
基于四个 ARGB 组件(alpha、红色、绿色和蓝色)值创建 Color 结构。Creates a Color structure from the four ARGB component (alpha, red, green, and blue) values. 尽管此方法允许为每个组件传递 32 位值,但每个组件的值仅限于 8 位。Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits. |
FromKnownColor(KnownColor) |
基于指定的预定义颜色创建 Color 结构。Creates a Color structure from the specified predefined color. |
FromName(String) |
基于预定义颜色的指定名称创建 Color 结构。Creates a Color structure from the specified name of a predefined color. |
GetBrightness() |
获取此 Color 结构的“色调-饱和度-亮度”(HSL) 的亮度值。Gets the hue-saturation-lightness (HSL) lightness value for this Color structure. |
GetHashCode() |
返回此 Color 结构的哈希代码。Returns a hash code for this Color structure. |
GetHue() |
获取此 Color 结构的“色调-饱和度-亮度”(HSL) 的色调值,以度为单位。Gets the hue-saturation-lightness (HSL) hue value, in degrees, for this Color structure. |
GetSaturation() |
获取此 Color 结构的“色调-饱和度-亮度”(HSL) 的饱和度值。Gets the hue-saturation-lightness (HSL) saturation value for this Color structure. |
ToArgb() |
获取此 Color 结构的 32 位 ARGB 值。Gets the 32-bit ARGB value of this Color structure. |
ToKnownColor() |
获取此 Color 结构的 KnownColor 值。Gets the KnownColor value of this Color structure. |
ToString() |
将此 Color 结构转换为用户可读的字符串。Converts this Color structure to a human-readable string. |
操作员
Equality(Color, Color) |
测试两个指定的 Color 结构是否等效。Tests whether two specified Color structures are equivalent. |
Inequality(Color, Color) |
测试两个指定的 Color 结构是否不同。Tests whether two specified Color structures are different. |