Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

PathGradientBrush.SetSigmaBellShape Method (Single, Single)

Creates a gradient brush that changes color starting from the center of the path outward to the path's boundary. The transition from one color to another is based on a bell-shaped curve.

Namespace:  System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)
public void SetSigmaBellShape(
	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 SetSigmaBellShape 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 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 SetSigmaBellShapeExample(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 blend.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);

    // Set the Blend factors and transform the brush.
    myPGBrush.SetSigmaBellShape(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 setting the 
    // blend and applying the transform.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300);
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.