Blend.Positions 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置渐变的混合位置的数组。
public:
property cli::array <float> ^ Positions { cli::array <float> ^ get(); void set(cli::array <float> ^ value); };
public float[] Positions { get; set; }
member this.Positions : single[] with get, set
Public Property Positions As Single()
属性值
Single[]
混合位置的数组,这些位置指定沿渐变线距离的百分比。
示例
下面的代码示例演示如何通过设置 Factors 和 Positions 属性来使用 Blend 类。 此示例旨在与 Windows 窗体 一起使用。 将代码粘贴到导入命名空间的窗体中 System.Drawing.Drawing2D 。 处理窗体的 Paint 事件并调用 DemonstrateBlend
方法,作为 e
PaintEventArgs传递。
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.2f 指定此点是距离起点总距离的 20%。 此数组中的元素由介于 0.0f 和 1.0f 之间的浮点值表示。 数组的第一个元素必须为 0.0f,最后一个元素必须为 1.0f。