This documentation is archived and is not being maintained.

Matrix.Rotate Method

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

Overload List

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

[Visual Basic] Overloads Public Sub Rotate(Single)
[C#] public void Rotate(float);
[C++] public: void Rotate(float);
[JScript] public function Rotate(float);

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

[Visual Basic] Overloads Public Sub Rotate(Single, MatrixOrder)
[C#] public void Rotate(float, MatrixOrder);
[C++] public: void Rotate(float, MatrixOrder);
[JScript] public function Rotate(float, MatrixOrder);

Example

[Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint 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).

[Visual Basic, C#] Notice that the red rectangle has been rotated around the 0, 0 screen coordinates.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of Rotate. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub RotateExample(e As PaintEventArgs)
Dim myPen As New Pen(Color.Blue, 1)
Dim myPen2 As 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.
Dim myMatrix As 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)
End Sub
        
[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);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Matrix Class | Matrix Members | System.Drawing.Drawing2D Namespace

Show: