Export (0) Print
Expand All

PathGradientBrush.RotateTransform Method (Single, MatrixOrder)

Rotates the local geometric transform by the specified amount in the specified order.

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

public void RotateTransform(
	float angle,
	MatrixOrder order
)

Parameters

angle
Type: System.Single

The angle (extent) of rotation.

order
Type: System.Drawing.Drawing2D.MatrixOrder

A MatrixOrder that specifies whether to append or prepend the rotation matrix.

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 rotate transform.

  • Applies the rotate transform to the brush by using its RotateTransform method.

  • Draws the rotated brush (rectangle) to the screen.

Notice that the bottom rectangle is rotated 45 degrees as compared to the one drawn prior to the translation.

public void RotateTransformExample(PaintEventArgs e)
{

    // Create a graphics path and add an ellipse.
    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 transformation.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);

    // Apply the rotate transform to the brush.
    myPGBrush.RotateTransform(45, MatrixOrder.Append);

    // Draw the brush to the screen again after applying the 
    // transform.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300);
}

.NET Framework

Supported in: 4.5.2, 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 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.

Show:
© 2014 Microsoft