Matrix.Translate 方法

定义

通过预先计算转换向量,将指定的转换向量应用到此 MatrixApplies the specified translation vector to this Matrix by prepending the translation vector.

重载

Translate(Single, Single)

通过预先计算转换向量,将指定的转换向量(offsetXoffsetY)应用到此 MatrixApplies the specified translation vector (offsetX and offsetY) to this Matrix by prepending the translation vector.

Translate(Single, Single, MatrixOrder)

按指定的顺序,将指定的转换向量应用到此 MatrixApplies the specified translation vector to this Matrix in the specified order.

Translate(Single, Single)

通过预先计算转换向量,将指定的转换向量(offsetXoffsetY)应用到此 MatrixApplies the specified translation vector (offsetX and offsetY) to this Matrix by prepending the translation vector.

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 值,通过它转换此 MatrixThe x value by which to translate this Matrix.

offsetY
Single

y 值,通过它转换此 MatrixThe y value by which to translate this Matrix.

示例

有关示例,请参见 Translate(Single, Single, MatrixOrder)For an example, see Translate(Single, Single, MatrixOrder).

适用于

Translate(Single, Single, MatrixOrder)

按指定的顺序,将指定的转换向量应用到此 MatrixApplies the specified translation vector to this Matrix in the specified order.

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 值,通过它转换此 MatrixThe x value by which to translate this Matrix.

offsetY
Single

y 值,通过它转换此 MatrixThe y value by which to translate this Matrix.

order
MatrixOrder

一个 MatrixOrder,指定将转换应用到此 Matrix 所采用的顺序(追加或预先计算)。A MatrixOrder that specifies the order (append or prepend) in which the translation is applied to this Matrix.

示例

下面的代码示例旨在与 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 translate transform (the blue rectangle).

  • 创建一个矩阵并在两个轴中将其转换为100。Creates a matrix and translates it by 100 in both axes.

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

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

请注意,红色矩形的开头位于蓝色三角形开头的两个轴中的100点。Notice that the beginning of the red rectangle is located 100 points in both axes from the beginning of the blue triangle.

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

适用于