Matrix.RotateAt 方法

定义

通过预先计算旋转,沿指定点顺时针旋转该 MatrixApplies a clockwise rotation about the specified point to this Matrix by prepending the rotation.

重载

RotateAt(Single, PointF)

沿 point 参数中指定的点并通过预先计算该旋转,来顺时针旋转此 MatrixApplies a clockwise rotation to this Matrix around the point specified in the point parameter, and by prepending the rotation.

RotateAt(Single, PointF, MatrixOrder)

按指定的顺序,沿指定点顺时针旋转该 MatrixApplies a clockwise rotation about the specified point to this Matrix in the specified order.

RotateAt(Single, PointF)

沿 point 参数中指定的点并通过预先计算该旋转,来顺时针旋转此 MatrixApplies a clockwise rotation to this Matrix around the point specified in the point parameter, and by prepending the rotation.

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

旋转角度(范围)(单位:度)。The angle (extent) of the rotation, in degrees.

point
PointF

一个 PointF,表示旋转中心。A PointF that represents the center of the rotation.

示例

下面的代码示例演示如何使用 MatrixTransform 方法来旋转字符串。The following code example demonstrates using a Matrix and the Transform method to rotate a string. 此示例旨在与 Windows 窗体一起使用。This example is designed to be used with Windows Forms. 创建窗体并将以下代码粘贴到其中。Create a form and paste the following code into it. DrawVerticalStringFromBottomUp在窗体的 Paint 事件处理程序中调用方法,并 e 以形式传递 PaintEventArgsCall the DrawVerticalStringFromBottomUp method in the form's Paint event handler, passing e as PaintEventArgs.

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)

按指定的顺序,沿指定点顺时针旋转该 MatrixApplies a clockwise rotation about the specified point to this Matrix in the specified order.

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

旋转的角度(单位:度)。The angle of the rotation, in degrees.

point
PointF

一个 PointF,表示旋转中心。A PointF that represents the center of the rotation.

order
MatrixOrder

一个 MatrixOrder,它指定旋转的顺序(追加或预先计算)。A MatrixOrder that specifies the order (append or prepend) in which the rotation is applied.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要 PaintEventArgs e 一个 Paint 事件对象。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, 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).

  • 创建一个矩阵并围绕指定点旋转45度。Creates a matrix and rotates it 45 degrees around a specified point.

  • 将此矩阵转换应用到矩形。Applies this matrix transform is to the rectangle.

  • 将已转换的矩形绘制到) 红色矩形 (屏幕。Draws the transformed rectangle to the screen (the red rectangle).

请注意,红色矩形已围绕矩形左上角旋转, (旋转点指定了 RotateAt 方法) 。Notice that the red rectangle has been rotated around the upper left-hand corner of the rectangle (the rotation point specified the RotateAt method).

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

适用于