PathGradientBrush.SetBlendTriangularShape 方法      
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建一个渐变,其中心颜色和线性下降到一个周围颜色。
重载
| SetBlendTriangularShape(Single) | 创建一个渐变,其中心颜色和线性下降到一个周围颜色。 | 
| SetBlendTriangularShape(Single, Single) | 创建具有中心颜色的渐变,以及每个周围颜色的线性回落。 | 
SetBlendTriangularShape(Single)
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
创建一个渐变,其中心颜色和线性下降到一个周围颜色。
public:
 void SetBlendTriangularShape(float focus);public void SetBlendTriangularShape (float focus);member this.SetBlendTriangularShape : single -> unitPublic Sub SetBlendTriangularShape (focus As Single)参数
- focus
- Single
一个介于 0 到 1 的值,该值指定从路径中心到路径边界的任何径向位置,中心颜色将处于其最高强度。 值为 1(默认值)将最高强度置于路径的中心。
示例
有关示例,请参阅 SetBlendTriangularShape.
注解
如果 SurroundColors 数组中有多个颜色,则数组中的第一种颜色用于结束颜色。 此数组中指定的颜色用于画笔边界路径上的离散点。
适用于
SetBlendTriangularShape(Single, Single)
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
- Source:
- PathGradientBrush.cs
创建具有中心颜色的渐变,以及每个周围颜色的线性回落。
public:
 void SetBlendTriangularShape(float focus, float scale);public void SetBlendTriangularShape (float focus, float scale);member this.SetBlendTriangularShape : single * single -> unitPublic Sub SetBlendTriangularShape (focus As Single, scale As Single)参数
- focus
- Single
一个介于 0 到 1 的值,该值指定从路径中心到路径边界的任何径向位置,中心颜色将处于其最高强度。 值为 1(默认值)将最高强度置于路径的中心。
- scale
- Single
一个介于 0 到 1 的值,该值指定与边界颜色混合的中心颜色的最大强度。 值为 1 会导致中心颜色的可能强度最高,它是默认值。
示例
下面的代码示例旨在与 Windows 窗体一起使用,它需要 PaintEventArgseOnPaint 事件对象。 该代码执行以下操作:
- 创建图形路径并为其添加一个矩形。 
- 从路径点创建 PathGradientBrush(在此示例中,这些点构成矩形,但它可以是大多数形状)。 
- 将中心颜色设置为红色,将周围颜色设置为蓝色。 
- 在应用混合转换之前,将 PathGradientBrush 绘制到屏幕。 
- 使用其 SetBlendTriangularShape 方法将混合转换应用于画笔。 
- 调用 TranslateTransform 方法移动画笔矩形,使其不会覆盖前面绘制到屏幕的画笔矩形。 
- 绘制已转换的画笔矩形将绘制到屏幕。 
请注意,最大中心颜色(红色)位于路径中心到路径边界的一半处。
public:
   void SetBlendTriangularShapeExample( PaintEventArgs^ e )
   {
      // Create a graphics path and add a rectangle.
      GraphicsPath^ myPath = gcnew GraphicsPath;
      Rectangle rect = Rectangle(100,20,100,50);
      myPath->AddRectangle( rect );
      // Get the path's array of points.
      array<PointF>^myPathPointArray = myPath->PathPoints;
      // Create a path gradient brush.
      PathGradientBrush^ myPGBrush = gcnew PathGradientBrush( myPathPointArray );
      // Set the color span.
      myPGBrush->CenterColor = Color::Red;
      array<Color>^ mySurroundColor = {Color::Blue};
      myPGBrush->SurroundColors = mySurroundColor;
      // Draw the brush to the screen prior to the blend.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 200, 200 );
      // Set the Blend factors.
      myPGBrush->SetBlendTriangularShape( 0.5f, 1.0f );
      // Move the brush down by 100 by Applying the translate
      // transform to the brush.
      myPGBrush->TranslateTransform( 0, 100, MatrixOrder::Append );
      // Draw the brush to the screen again after applying the
      // transforms.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 300, 300 );
   }
public void SetBlendTriangularShapeExample(PaintEventArgs e)
{
             
    // Create a graphics path and add a rectangle.
    GraphicsPath myPath = new GraphicsPath();
    Rectangle rect = new Rectangle(100, 20, 100, 50);
    myPath.AddRectangle(rect);
             
    // Get the path's array of points.
    PointF[] myPathPointArray = myPath.PathPoints;
             
    // Create a path gradient brush.
    PathGradientBrush myPGBrush = new
        PathGradientBrush(myPathPointArray);
             
    // Set the color span.
    myPGBrush.CenterColor = Color.Red;
    Color[] mySurroundColor = {Color.Blue};
    myPGBrush.SurroundColors = mySurroundColor;
             
    // Draw the brush to the screen prior to the blend.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
             
    // Set the Blend factors.
    myPGBrush.SetBlendTriangularShape(0.5f, 1.0f);
             
    // Move the brush down by 100 by Applying the translate
    // transform to the brush.
    myPGBrush.TranslateTransform(0, 100, MatrixOrder.Append);
             
    // Draw the brush to the screen again after applying the
    // transforms.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300);
}
Public Sub SetBlendTriangularShapeExample(ByVal e As PaintEventArgs)
    ' Create a graphics path and add a rectangle.
    Dim myPath As New GraphicsPath
    Dim rect As New Rectangle(100, 20, 100, 50)
    myPath.AddRectangle(rect)
    ' Get the path's array of points.
    Dim myPathPointArray As PointF() = myPath.PathPoints
    ' Create a path gradient brush.
    Dim myPGBrush As New PathGradientBrush(myPathPointArray)
    ' Set the color span.
    myPGBrush.CenterColor = Color.Red
    Dim mySurroundColor As Color() = {Color.Blue}
    myPGBrush.SurroundColors = mySurroundColor
    ' Draw the brush to the screen prior to blend.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200)
    ' Set the Blend factors.
    myPGBrush.SetBlendTriangularShape(0.5F, 1.0F)
    ' Move the brush down by 100 by Applying the translate
    ' transform to the brush.
    myPGBrush.TranslateTransform(0, 100, MatrixOrder.Append)
    ' Draw the brush to the screen again after applying the
    ' transforms.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300)
End Sub
注解
如果 SurroundColors 数组中有多个颜色,则数组中的第一种颜色用于结束颜色。 此数组中指定的颜色是用于画笔边界路径上离散点的颜色。
默认情况下,当从路径渐变的边界移动到中心点时,颜色会逐渐从边界颜色更改为中心颜色。 可以通过调用此方法来自定义边界和中心颜色的定位和混合。