GraphicsPath.Transform(Matrix) Method

Definition

Applies a transform matrix to this GraphicsPath.

C#
public void Transform(System.Drawing.Drawing2D.Matrix matrix);

Parameters

matrix
Matrix

A Matrix that represents the transformation to apply.

Examples

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

C#
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);
}

Remarks

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

Applies to

Proizvod Verzije
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10