PathGradientBrush.MultiplyTransform Method (Matrix, MatrixOrder)


Updates the brush's transformation matrix with the product of the brush's transformation matrix multiplied by another matrix.

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

public void MultiplyTransform(
	Matrix matrix,
	MatrixOrder order


Type: System.Drawing.Drawing2D.Matrix

The Matrix that will be multiplied by the brush's current transformation matrix.

Type: System.Drawing.Drawing2D.MatrixOrder

A MatrixOrder that specifies in which order to multiply the two matrices.

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

  • Creates s matrix that rotates the brush 90 degrees and translates it by 100 in both axes.

  • Applies this matrix to the brush by using the MultiplyTransform method.

  • Draws the brush to the screen.

public void MultiplyTransformExample(PaintEventArgs e)

    // Create a graphics path and add an rectangle.
    GraphicsPath myPath = new GraphicsPath();
    Rectangle rect = new Rectangle(20, 20, 100, 50);

    // Get the path's array of points.
    PointF[] myPathPointArray = myPath.PathPoints;

    // Create a path gradient brush.
    PathGradientBrush myPGBrush = new

    // 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);

    // Create a new matrix that rotates by 90 degrees, and
    // translates by 100 in each direction.
    Matrix myMatrix = new Matrix(0, 1, -1, 0, 100, 100);

    // Apply the transform to the brush.
    myPGBrush.MultiplyTransform(myMatrix, 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