Export (0) Print
Expand All

PathGradientBrush.SetBlendTriangularShape Method

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

Overload List

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

[Visual Basic] Overloads Public Sub SetBlendTriangularShape(Single)
[C#] public void SetBlendTriangularShape(float);
[C++] public: void SetBlendTriangularShape(float);
[JScript] public function SetBlendTriangularShape(float);

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

[Visual Basic] Overloads Public Sub SetBlendTriangularShape(Single, Single)
[C#] public void SetBlendTriangularShape(float, float);
[C++] public: void SetBlendTriangularShape(float, float);
[JScript] public function SetBlendTriangularShape(float, float);

Example

[Visual Basic, C#] The following 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.

[Visual Basic, C#] Notice that the maximum center color (red) is located half way from the center of the path to the path boundary.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of SetBlendTriangularShape. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub SetBlendTriangularShapeExample(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, 1F)
' 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
        
[C#] 
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);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

PathGradientBrush Class | PathGradientBrush Members | System.Drawing.Drawing2D Namespace

Show:
© 2014 Microsoft