Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
SetBlendTriangularShape Method (Single, Single)
Collapse the table of content
Expand the table of content

PathGradientBrush.SetBlendTriangularShape Method (Single, Single)

Creates a gradient with a center color and a linear falloff to each surrounding color.

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

public void SetBlendTriangularShape(
	float focus,
	float scale
)

Parameters

focus
Type: System.Single

A value from 0 through 1 that specifies where, along any radial from the center of the path to the path's boundary, the center color will be at its highest intensity. A value of 1 (the default) places the highest intensity at the center of the path.

scale
Type: System.Single

A value from 0 through 1 that specifies the maximum intensity of the center color that gets blended with the boundary color. A value of 1 causes the highest possible intensity of the center color, and it is the default value.

If there is more than one color in the SurroundColors array, the first color in the array is used for the ending color. The colors specified in this array are colors used for discrete points on the brush's boundary path.

By default, as you move from the boundary of a path gradient to the center point, the color changes gradually from the boundary color to the center color. You can customize the positioning and blending of the boundary and center colors by calling this method.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code performs the following actions:

  • Creates a graphics path and adds a rectangle to it.

  • Creates a PathGradientBrush from the path points (in this example, the points form a rectangle, but it could be most any shape).

  • Sets the center color to red and the surrounding color to blue.

  • Draws the PathGradientBrush to the screen prior to applying the blend transform.

  • Applies the blend transform to the brush by using its SetBlendTriangularShape method.

  • Calls the TranslateTransform method to move the brush rectangle such that it does not overlay the one drawn to the screen earlier.

  • Draws the transformed-brush rectangle is drawn to the screen.

Notice that the maximum center color (red) is located half way from the center of the path to the path boundary.

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);
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft