Color.R 属性

定义

获取此 Color 结构的红色组件值。

C#
public byte R { get; }

属性值

Color 的红色分量值。

示例

下面的代码示例演示 了 A和 成员的 ColorRGBImplicit 属性。

此示例旨在与 Windows 窗体一起使用。 将代码粘贴到窗体中, ShowPropertiesOfSlateBlue 并从窗体的事件 Paint 处理方法调用 方法,作为 ePaintEventArgs传递。

C#
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));
}

注解

每个像素的颜色表示为 32 位数字:alpha、红色、绿色和蓝色各 8 位, (ARGB) 。 四个分量中的每一个都是一个从 0 到 255 的数字,其中 0 表示无强度,而 255 表示全强度。 同样

R 是一个介于 0 到 255 的值,0 表示不红色,255 表示完全红色。

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1