GraphicsPath.Transform Method (Matrix)

 

Applies a transform matrix to this GraphicsPath.

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

public void Transform(
	Matrix matrix
)

Parameters

matrix
Type: System.Drawing.Drawing2D.Matrix

A Matrix that represents the transformation to apply.

The transformation can scale, translate, rotate, or skew the GraphicsPath.

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 path and adds an ellipse to the path.

  • Draws path to the screen.

  • Creates a transform matrix to translate the path 100 units in the x-axis direction.

  • Draws the transformed path to the screen.

Notice that the original ellipse is drawn in black and the transformed ellipse is drawn in red.

private void TransformExample(PaintEventArgs e)
{

    // Create a path and add and ellipse.
    GraphicsPath myPath = new GraphicsPath();
    myPath.AddEllipse(0, 0, 100, 200);

    // Draw the starting position to screen.
    e.Graphics.DrawPath(Pens.Black, myPath);

    // Move the ellipse 100 points to the right.
    Matrix translateMatrix = new Matrix();
    translateMatrix.Translate(100, 0);
    myPath.Transform(translateMatrix);

    // Draw the transformed ellipse to the screen.
    e.Graphics.DrawPath(new Pen(Color.Red, 2), myPath);
}

.NET Framework
Available since 1.1
Return to top
Show: