Matrix.Rotate Method

Definition

Applies a clockwise rotation of the specified angle about the origin to this Matrix.

Overloads

Rotate(Single)

Prepend to this Matrix a clockwise rotation, around the origin and by the specified angle.

Rotate(Single, MatrixOrder)

Applies a clockwise rotation of an amount specified in the angle parameter, around the origin (zero x and y coordinates) for this Matrix.

Rotate(Single)

Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs

Prepend to this Matrix a clockwise rotation, around the origin and by the specified angle.

C#
public void Rotate(float angle);

Parameters

angle
Single

The angle of the rotation, in degrees.

Examples

For an example, see Rotate(Single, MatrixOrder).

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.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

Rotate(Single, MatrixOrder)

Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs
Source:
Matrix.cs

Applies a clockwise rotation of an amount specified in the angle parameter, around the origin (zero x and y coordinates) for this Matrix.

C#
public void Rotate(float angle, System.Drawing.Drawing2D.MatrixOrder order);

Parameters

angle
Single

The angle (extent) of the rotation, in degrees.

order
MatrixOrder

A MatrixOrder that specifies the order (append or prepend) in which the rotation is applied to this Matrix.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, an Paint event object. The code performs the following actions:

  • Draws a rectangle to the screen prior to applying a rotation transform (the blue rectangle).

  • Creates a matrix and rotates it 45 degrees.

  • Applies this matrix transform to the rectangle.

  • Draws the transformed rectangle to the screen (the red rectangle).

Notice that the red rectangle has been rotated around the 0, 0 screen coordinates.

C#
public void RotateExample(PaintEventArgs e)
{
    Pen myPen = new Pen(Color.Blue, 1);
    Pen myPen2 = new Pen(Color.Red, 1);
             
    // Draw the rectangle to the screen before applying the transform.
    e.Graphics.DrawRectangle(myPen, 150, 50, 200, 100);
             
    // Create a matrix and rotate it 45 degrees.
    Matrix myMatrix = new Matrix();
    myMatrix.Rotate(45, MatrixOrder.Append);
             
    // Draw the rectangle to the screen again after applying the
             
    // transform.
    e.Graphics.Transform = myMatrix;
    e.Graphics.DrawRectangle(myPen2, 150, 50, 200, 100);
}

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.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