Color.B 屬性

定義

取得這個 Color 結構的藍色元件值。

C#
public byte B { get; }

屬性值

這個 Color 的藍色元件值。

範例

下列程式代碼範例示範A、 和 成員的ColorRGBImplicit 屬性。

此範例的設計目的是要與 Windows Form 搭配使用。 將程式代碼貼到表單中,並從表單Paint的事件處理方法呼叫 ShowPropertiesOfSlateBlue 方法,並e傳遞為 PaintEventArgs

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 位的數位表示:每 8 位代表 alpha、紅色、綠色和藍色 (ARGB) 。 四個元件中的每一個都是從 0 到 255 的數位,0 代表無濃度,255 代表完整強度。 同樣地,是介於 0 到 255 之間的值, B 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