Blend.Factors 属性

定义

获取或设置用于渐变的混合因子数组。

public:
 property cli::array <float> ^ Factors { cli::array <float> ^ get(); void set(cli::array <float> ^ value); };
public float[] Factors { get; set; }
member this.Factors : single[] with get, set
Public Property Factors As Single()

属性值

Single[]

混合因子数组,这些因子指定在相应位置处使用的起始色和结束色的百分比。

示例

下面的代码示例演示如何通过设置 FactorsPositions 属性来使用 Blend 类。 此示例旨在与 Windows 窗体 一起使用。 将代码粘贴到导入命名空间的窗体中 System.Drawing.Drawing2D 。 处理窗体的 Paint 事件并调用 DemonstrateBlend 方法,作为 ePaintEventArgs传递。

private:
   void DemonstrateBlend( PaintEventArgs^ e )
   {
      Blend^ blend1 = gcnew Blend( 9 );

      // Set the values in the Factors array to be all green, 
      // go to all blue, and then go back to green.
      array<Single>^temp0 = {0.0F,0.2F,0.5F,0.7F,1.0F,0.7F,0.5F,0.2F,0.0F};
      blend1->Factors = temp0;

      // Set the positions.
      array<Single>^temp1 = {0.0F,0.1F,0.3F,0.4F,0.5F,0.6F,0.7F,0.8F,1.0F};
      blend1->Positions = temp1;

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

      // Create a new LinearGradientBrush using the rectangle, 
      // green and blue. and 90-degree angle.
      LinearGradientBrush^ brush1 = gcnew 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.
      delete brush1;
   }
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();
}
Private Sub DemonstrateBlend(ByVal e As PaintEventArgs)
    Dim blend1 As 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 Single() {0.0F, 0.2F, 0.5F, 0.7F, 1.0F, _
        0.7F, 0.5F, 0.2F, 0.0F}

    ' Set the positions.
    blend1.Positions = New Single() {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.
    Dim rectangle1 As New Rectangle(10, 10, 120, 100)

    ' Create a new LinearGradientBrush using the rectangle, 
    ' green and blue. and 90-degree angle.
    Dim brush1 As 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()
End Sub

注解

通常,此数组的元素是介于 0.0f 到 1.0f 的值。 这些元素指定在相应混合位置使用的结束颜色和起始颜色的百分比。 例如,值 0.2 指示在指定位置,混合颜色由结束渐变颜色的 20% 和起始渐变颜色的 80% 组成。

适用于