Matrix.Translate 方法

定义

通过预先计算转换向量,将指定的转换向量应用到此 Matrix

重载

Translate(Single, Single)

通过预先计算转换向量,将指定的转换向量(offsetXoffsetY)应用到此 Matrix

Translate(Single, Single, MatrixOrder)

按指定的顺序,将指定的转换向量应用到此 Matrix

Translate(Single, Single)

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

通过预先计算转换向量,将指定的转换向量(offsetXoffsetY)应用到此 Matrix

public:
 void Translate(float offsetX, float offsetY);
public void Translate (float offsetX, float offsetY);
member this.Translate : single * single -> unit
Public Sub Translate (offsetX As Single, offsetY As Single)

参数

offsetX
Single

x 值,通过它转换此 Matrix

offsetY
Single

y 值,通过它转换此 Matrix

示例

有关示例,请参见 Translate(Single, Single, MatrixOrder)

适用于

Translate(Single, Single, MatrixOrder)

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

按指定的顺序,将指定的转换向量应用到此 Matrix

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

参数

offsetX
Single

x 值,通过它转换此 Matrix

offsetY
Single

y 值,通过它转换此 Matrix

order
MatrixOrder

一个 MatrixOrder,指定将转换应用到此 Matrix 所采用的顺序(追加或预先计算)。

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse事件Paint对象。 此代码执行以下操作:

  • 在 (蓝色矩形) 应用平移转换之前,在屏幕上绘制一个矩形。

  • 创建矩阵,并在两个轴中将其平移 100。

  • 将此矩阵转换应用于矩形,

  • 将转换后的矩形绘制到屏幕 (红色矩形) 。

请注意,红色矩形的开头位于两个轴中距蓝色三角形开头的 100 磅。

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

      // Draw a rectangle to the screen before applying the
      // transform.
      e->Graphics->DrawRectangle( myPen, 20, 20, 100, 50 );

      // Create a matrix and translate it.
      Matrix^ myMatrix = gcnew Matrix;
      myMatrix->Translate( 100, 100, MatrixOrder::Append );

      // Draw the Points to the screen again after applying the
      // transform.
      e->Graphics->Transform = myMatrix;
      e->Graphics->DrawRectangle( myPen2, 20, 20, 100, 50 );
   }
public void TranslateExample(PaintEventArgs e)
{
    Pen myPen = new Pen(Color.Blue, 1);
    Pen myPen2 = new Pen(Color.Red, 1);
             
    // Draw a rectangle to the screen before applying the
    // transform.
    e.Graphics.DrawRectangle(myPen, 20, 20, 100, 50);
             
    // Create a matrix and translate it.
    Matrix myMatrix = new Matrix();
    myMatrix.Translate(100, 100, MatrixOrder.Append);
             
    // Draw the Points to the screen again after applying the
    // transform.
    e.Graphics.Transform = myMatrix;
    e.Graphics.DrawRectangle(myPen2, 20, 20, 100, 50);
}
Public Sub TranslateExample(ByVal e As PaintEventArgs)
    Dim myPen As New Pen(Color.Blue, 1)
    Dim myPen2 As New Pen(Color.Red, 1)

    ' Draw a rectangle to the screen before applying the
    ' transform.
    e.Graphics.DrawRectangle(myPen, 20, 20, 100, 50)

    ' Create a matrix and translate it.
    Dim myMatrix As New Matrix
    myMatrix.Translate(100, 100, MatrixOrder.Append)

    ' Draw the Points to the screen again after applying the
    ' transform.
    e.Graphics.Transform = myMatrix
    e.Graphics.DrawRectangle(myPen2, 20, 20, 100, 50)
End Sub

适用于