Blend.Positions 屬性

定義

取得或設定漸層的漸變位置陣列。

C#
public float[] Positions { get; set; }

屬性值

Single[]

漸變位置的陣列,指定沿著漸層線的距離百分比。

範例

下列程式代碼範例示範如何藉由設定 FactorsPositions 屬性來使用 Blend 類別。 此範例的設計目的是要與 Windows Forms 搭配使用。 將程式代碼貼到匯入命名空間的 System.Drawing.Drawing2D 表單中。 處理表單的事件 Paint 並呼叫 DemonstrateBlend 方法,並 e 傳遞為 PaintEventArgs

C#
private void DemonstrateBlend(PaintEventArgs e)
{
    Blend blend1 = new Blend(9);

    // Set the values in the Factors array to be all green, 
    // go to all blue, and then go back to green.
    blend1.Factors = new float[]{0.0F, 0.2F, 0.5F, 0.7F, 1.0F, 
                                    0.7F, 0.5F, 0.2F, 0.0F};

    // Set the positions.
    blend1.Positions = 
        new float[]{0.0F, 0.1F, 0.3F, 0.4F, 0.5F, 0.6F, 
        0.7F, 0.8F, 1.0F};

    // Declare a rectangle to draw the Blend in.
    Rectangle rectangle1 = new Rectangle(10, 10, 120, 100);

    // Create a new LinearGradientBrush using the rectangle, 
    // green and blue. and 90-degree angle.
    LinearGradientBrush brush1 = 
        new LinearGradientBrush(rectangle1, Color.LightGreen, 
        Color.Blue, 90, true);

    // Set the Blend property on the brush to the custom blend.
    brush1.Blend = blend1;

    // Fill in an ellipse with the brush.
    e.Graphics.FillEllipse(brush1, rectangle1);

    // Dispose of the custom brush.
    brush1.Dispose();
}

備註

此陣列的專案會指定沿著漸層線的距離百分比。 例如,元素值 0.2f 指定這個點是起點總距離的 20%。 此陣列中的元素是以介於0.0f和1.0f之間的浮點值來表示。 陣列的第一個項目必須是0.0f,而最後一個項目必須是1.0f。

適用於

產品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9