Matrix.RotateAt 方法

定義

藉由預先規劃旋轉,將繞著指定點的順時針旋轉套用至這個 Matrix

多載

RotateAt(Single, PointF)

藉由預先規劃旋轉,繞著 point 參數中所指定的點,將順時針旋轉套用至這個 Matrix

RotateAt(Single, PointF, MatrixOrder)

依據指定的順序,將繞著指定點的順時針旋轉套用至這個 Matrix

RotateAt(Single, PointF)

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

藉由預先規劃旋轉,繞著 point 參數中所指定的點,將順時針旋轉套用至這個 Matrix

public:
 void RotateAt(float angle, System::Drawing::PointF point);
public void RotateAt (float angle, System.Drawing.PointF point);
member this.RotateAt : single * System.Drawing.PointF -> unit
Public Sub RotateAt (angle As Single, point As PointF)

參數

angle
Single

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

point
PointF

PointF,表示旋轉的中心。

範例

下列程式代碼範例示範如何使用 MatrixTransform 方法來旋轉字串。 此範例的設計目的是要與 Windows Forms 搭配使用。 Create 表單,並將下列程式代碼貼到窗體中。 DrawVerticalStringFromBottomUp在表單的Paint事件處理程式中呼叫 方法,傳遞ePaintEventArgs

private:
   void DrawVerticalStringFromBottomUp( PaintEventArgs^ e )
   {
      // Create the string to draw on the form.
      String^ text = "Can you read this?";

      // Create a GraphicsPath.
      System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath;

      // Add the string to the path; declare the font, font style, size, and
      // vertical format for the string.
      path->AddString( text, this->Font->FontFamily, 1, 15, PointF(0.0F,0.0F), gcnew StringFormat( StringFormatFlags::DirectionVertical ) );

      // Declare a matrix that will be used to rotate the text.
      System::Drawing::Drawing2D::Matrix^ rotateMatrix = gcnew System::Drawing::Drawing2D::Matrix;

      // Set the rotation angle and starting point for the text.
      rotateMatrix->RotateAt( 180.0F, PointF(10.0F,100.0F) );

      // Transform the text with the matrix.
      path->Transform(rotateMatrix);

      // Set the SmoothingMode to high quality for best readability.
      e->Graphics->SmoothingMode = System::Drawing::Drawing2D::SmoothingMode::HighQuality;

      // Fill in the path to draw the string.
      e->Graphics->FillPath( Brushes::Red, path );

      // Dispose of the path.
      delete path;
   }
public void DrawVerticalStringFromBottomUp(PaintEventArgs e)
{

    // Create the string to draw on the form.
    string text = "Can you read this?";

    // Create a GraphicsPath.
    System.Drawing.Drawing2D.GraphicsPath path = 
        new System.Drawing.Drawing2D.GraphicsPath();

    // Add the string to the path; declare the font, font style, size, and
    // vertical format for the string.
    path.AddString(text, this.Font.FontFamily, 1, 15, 
        new PointF(0.0F, 0.0F), 
        new StringFormat(StringFormatFlags.DirectionVertical));

    // Declare a matrix that will be used to rotate the text.
    System.Drawing.Drawing2D.Matrix rotateMatrix = 
        new System.Drawing.Drawing2D.Matrix();

    // Set the rotation angle and starting point for the text.
    rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F));

    // Transform the text with the matrix.
    path.Transform(rotateMatrix);

    // Set the SmoothingMode to high quality for best readability.
    e.Graphics.SmoothingMode = 
        System.Drawing.Drawing2D.SmoothingMode.HighQuality;

    // Fill in the path to draw the string.
    e.Graphics.FillPath(Brushes.Red, path);

    // Dispose of the path.
    path.Dispose();
}
Public Sub DrawVerticalStringFromBottomUp(ByVal e As PaintEventArgs)

    ' Create the string to draw on the form.
    Dim text As String = "Can you read this?"

    ' Create a GraphicsPath.
    Dim path As New System.Drawing.Drawing2D.GraphicsPath

    ' Add the string to the path; declare the font, font style, size, and
    ' vertical format for the string.
    path.AddString(text, Me.Font.FontFamily, 1, 15, New PointF(0.0F, 0.0F), _
        New StringFormat(StringFormatFlags.DirectionVertical))

    ' Declare a matrix that will be used to rotate the text.
    Dim rotateMatrix As New System.Drawing.Drawing2D.Matrix

    ' Set the rotation angle and starting point for the text.
    rotateMatrix.RotateAt(180.0F, New PointF(10.0F, 100.0F))

    ' Transform the text with the matrix.
    path.Transform(rotateMatrix)

    ' Set the SmoothingMode to high quality for best readability.
    e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

    ' Fill in the path to draw the string.
    e.Graphics.FillPath(Brushes.Red, path)

    ' Dispose of the path.
    path.Dispose()

End Sub

適用於

RotateAt(Single, PointF, MatrixOrder)

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

依據指定的順序,將繞著指定點的順時針旋轉套用至這個 Matrix

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

參數

angle
Single

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

point
PointF

PointF,表示旋轉的中心。

order
MatrixOrder

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

範例

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

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

  • 建立矩陣,並將它繞著指定的點旋轉 45 度。

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

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

請注意,紅色矩形已繞矩形左上角旋轉, (指定 RotateAt 方法) 的旋轉點。

public:
   void RotateAtExample( PaintEventArgs^ e )
   {
      Pen^ myPen = gcnew Pen( Color::Blue,1.0f );
      Pen^ myPen2 = gcnew Pen( Color::Red,1.0f );
      PointF rotatePoint = PointF(150.0f,50.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->RotateAt( 45, rotatePoint, 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 RotateAtExample(PaintEventArgs e)
{
    Pen myPen = new Pen(Color.Blue, 1);
    Pen myPen2 = new Pen(Color.Red, 1);
    PointF rotatePoint = new PointF(150.0f, 50.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 = new Matrix();
    myMatrix.RotateAt(45, rotatePoint, 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 RotateAtExample(ByVal e As PaintEventArgs)
    Dim myPen As New Pen(Color.Blue, 1)
    Dim myPen2 As New Pen(Color.Red, 1)
    Dim rotatePoint As New PointF(150.0F, 50.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.
    Dim myMatrix As New Matrix
    myMatrix.RotateAt(45, rotatePoint, 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

適用於