Matrix.Rotate 方法

定義

將繞著原點之指定角度的順時針旋轉套用至這個 Matrix

多載

Rotate(Single)

在原點為中心並以指定的角度,預先規劃這個 Matrix 的順時針旋轉。

Rotate(Single, MatrixOrder)

以這個 Matrix 的原點 (X 座標和 Y 座標都為 0) 為中心,套用 angle 參數中指定的順時針旋轉量。

Rotate(Single)

來源:
Matrix.cs
來源:
Matrix.cs
來源:
Matrix.cs

在原點為中心並以指定的角度,預先規劃這個 Matrix 的順時針旋轉。

public:
 void Rotate(float angle);
public void Rotate (float angle);
member this.Rotate : single -> unit
Public Sub Rotate (angle As Single)

參數

angle
Single

旋轉的角度,單位為度數。

範例

如需範例,請參閱 Rotate(Single, MatrixOrder)

適用於

Rotate(Single, MatrixOrder)

來源:
Matrix.cs
來源:
Matrix.cs
來源:
Matrix.cs

以這個 Matrix 的原點 (X 座標和 Y 座標都為 0) 為中心,套用 angle 參數中指定的順時針旋轉量。

public:
 void Rotate(float angle, System::Drawing::Drawing2D::MatrixOrder order);
public void Rotate (float angle, System.Drawing.Drawing2D.MatrixOrder order);
member this.Rotate : single * System.Drawing.Drawing2D.MatrixOrder -> unit
Public Sub Rotate (angle As Single, order As MatrixOrder)

參數

angle
Single

旋轉的角度 (範圍),單位為度數。

order
MatrixOrder

MatrixOrder,指定將旋轉套用至這個 Matrix 的順序 (附加或預先規劃)。

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse事件Paint物件。 此程式碼會執行下列動作:

  • 在套用旋轉轉換之前,先將矩形繪製到畫面, (藍色矩形) 。

  • 建立矩陣並旋轉 45 度。

  • 將此矩陣轉換套用至矩形。

  • 將轉換的矩形繪製到畫面, (紅色矩形) 。

請注意,紅色矩形已繞著0、0螢幕座標旋轉。

public:
   void RotateExample( PaintEventArgs^ e )
   {
      Pen^ myPen = gcnew Pen( Color::Blue,1.0f );
      Pen^ myPen2 = gcnew Pen( Color::Red,1.0f );

      // 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 = gcnew 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 );
   }
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);
}
Public Sub RotateExample(ByVal 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

適用於