Matrix.Translate 方法

定義

藉由預先規劃轉換向量,將指定的轉換向量套用至這個 Matrix

多載

Translate(Single, Single)

藉由預先規劃轉換向量,將指定的轉換向量 (offsetXoffsetY) 套用至這個 Matrix

Translate(Single, Single, MatrixOrder)

依據指定的順序,將指定的轉換向量套用至這個 Matrix

Translate(Single, Single)

來源:
Matrix.cs
來源:
Matrix.cs
來源:
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

用來轉換這個 Matrix 的 x 值。

offsetY
Single

用來轉換這個 Matrix 的 y 值。

範例

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

適用於

Translate(Single, Single, MatrixOrder)

來源:
Matrix.cs
來源:
Matrix.cs
來源:
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

用來轉換這個 Matrix 的 x 值。

offsetY
Single

用來轉換這個 Matrix 的 y 值。

order
MatrixOrder

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

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 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

適用於