Export (0) Print
Expand All

Blend.Positions Property

Gets or sets an array of blend positions for the gradient.

Namespace: System.Drawing.Drawing2D
Assembly: System.Drawing (in system.drawing.dll)

public float[] Positions { get; set; }
/** @property */
public float[] get_Positions ()

/** @property */
public void set_Positions (float[] value)

public function get Positions () : float[]

public function set Positions (value : float[])

Not applicable.

Property Value

An array of blend positions that specify the percentages of distance along the gradient line.

The elements of this array specify percentages of distance along the gradient line. For example, an element value of 0.2f specifies that this point is 20 percent of the total distance from the starting point. The elements in this array are represented by float values between 0.0f and 1.0f. The first element of the array must be 0.0f, and the last element must be 1.0f.

The following code example demonstrates how to use the Blend class by setting the Factors and Positions properties. This example is designed to be used with Windows Forms. Paste the code into a form that imports the System.Drawing.Drawing2D namespace. Handle the form's Paint event and call the DemonstrateBlend method, passing e as PaintEventArgs.

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 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.set_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.set_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.get_LightGreen(), Color.get_Blue(),
                                90, true);

    // Set the Blend property on the brush to the custom blend.
    brush1.set_Blend(blend1);

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

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



Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft