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 PaintEventArgse, 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
Available since 1.1
Return to top
Show: