Color.R Color.R Color.R Color.R Property

定义

获取此 Color 结构的红色组件值。Gets the red component value of this Color structure.

public:
 property System::Byte R { System::Byte get(); };
public byte R { get; }
member this.R : byte
Public ReadOnly Property R As Byte

属性值

Color 的红色分量值。The red component value of this Color.

示例

下面的代码示例演示ARG,和B的属性Color,并且Implicit成员。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. 将代码粘贴到窗体并调用ShowPropertiesOfSlateBlue方法从窗体的Paint事件处理方法,传递e作为PaintEventArgsPaste 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

注解

每个像素的颜色表示为一个 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. 同样,Likewise,

R 是一个介于 0 到 255 之间,其中 0 表示没有红色,255 表示完全红色。R is a value from 0 to 255 with 0 representing no red and 255 representing fully red.

适用于