Graphics.TranslateTransform 方法

定義

透過將指定的轉譯放置在此 Graphics 的轉換矩陣之前,變更座標系統的原點。

多載

TranslateTransform(Single, Single, MatrixOrder)

依照指定的順序,將指定之轉換套用至這個 Graphics 的變換矩陣,以變更座標系統的原點。

TranslateTransform(Single, Single)

透過將指定的轉譯放置在此 Graphics 的轉換矩陣之前,變更座標系統的原點。

TranslateTransform(Single, Single, MatrixOrder)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

依照指定的順序,將指定之轉換套用至這個 Graphics 的變換矩陣,以變更座標系統的原點。

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

參數

dx
Single

這個轉譯的 X 座標。

dy
Single

這個轉譯的 Y 座標。

order
MatrixOrder

MatrixOrder 列舉的成員,指定轉換是附加到變換矩陣之前或之後。

範例

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

  • 旋轉 Windows Form 世界轉換矩陣 30.0F 度。

  • 藉由呼叫 TranslateTransform來移動圖形物件的原點,並將翻譯附加至世界轉換矩陣。

  • 使用藍色畫筆繪製旋轉的翻譯橢圓形。

public:
   void TranslateTransformAngleMatrixOrder( PaintEventArgs^ e )
   {
      // Set world transform of graphics object to rotate.
      e->Graphics->RotateTransform( 30.0F );

      // Then to translate, appending to world transform.
      e->Graphics->TranslateTransform( 100.0F, 0.0F, MatrixOrder::Append );

      // Draw rotated, translated ellipse to screen.
      e->Graphics->DrawEllipse( gcnew Pen( Color::Blue,3.0f ), 0, 0, 200, 80 );
   }
private void TranslateTransformAngleMatrixOrder(PaintEventArgs e)
{

    // Set world transform of graphics object to rotate.
    e.Graphics.RotateTransform(30.0F);

    // Then to translate, appending to world transform.
    e.Graphics.TranslateTransform(100.0F, 0.0F, MatrixOrder.Append);

    // Draw rotated, translated ellipse to screen.
    e.Graphics.DrawEllipse(new Pen(Color.Blue, 3), 0, 0, 200, 80);
}
Private Sub TranslateTransformAngleMatrixOrder(ByVal e As PaintEventArgs)

    ' Set world transform of graphics object to rotate.
    e.Graphics.RotateTransform(30.0F)

    ' Then to translate, appending to world transform.
    e.Graphics.TranslateTransform(100.0F, 0.0F, MatrixOrder.Append)

    ' Draw rotated, translated ellipse to screen.
    e.Graphics.DrawEllipse(New Pen(Color.Blue, 3), 0, 0, 200, 80)
End Sub

備註

轉譯作業包含將轉換矩陣乘以其轉譯部分為 和 dy 參數的dx矩陣。 這個方法會根據 order 參數,在轉譯矩陣前面加上或附加 的Graphics轉換矩陣。

另請參閱

適用於

TranslateTransform(Single, Single)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

透過將指定的轉譯放置在此 Graphics 的轉換矩陣之前,變更座標系統的原點。

public:
 void TranslateTransform(float dx, float dy);
public void TranslateTransform (float dx, float dy);
member this.TranslateTransform : single * single -> unit
Public Sub TranslateTransform (dx As Single, dy As Single)

參數

dx
Single

這個轉譯的 X 座標。

dy
Single

這個轉譯的 Y 座標。

範例

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

  • 旋轉 Windows Form 世界轉換矩陣 30.0F 度。

  • 呼叫 ,在轉換矩陣前面加上轉譯,以移動圖形物件的 TranslateTransform原點。

  • 使用藍色畫筆繪製已翻譯的旋轉橢圓形。

public:
   void TranslateTransformAngle( PaintEventArgs^ e )
   {
      // Set world transform of graphics object to rotate.
      e->Graphics->RotateTransform( 30.0F );

      // Then to translate, prepending to world transform.
      e->Graphics->TranslateTransform( 100.0F, 0.0F );

      // Draw translated, rotated ellipse to screen.
      e->Graphics->DrawEllipse( gcnew Pen( Color::Blue,3.0f ), 0, 0, 200, 80 );
   }
private void TranslateTransformAngle(PaintEventArgs e)
{

    // Set world transform of graphics object to rotate.
    e.Graphics.RotateTransform(30.0F);

    // Then to translate, prepending to world transform.
    e.Graphics.TranslateTransform(100.0F, 0.0F);

    // Draw translated, rotated ellipse to screen.
    e.Graphics.DrawEllipse(new Pen(Color.Blue, 3), 0, 0, 200, 80);
}
Private Sub TranslateTransformAngle(ByVal e As PaintEventArgs)

    ' Set world transform of graphics object to rotate.
    e.Graphics.RotateTransform(30.0F)

    ' Then to translate, prepending to world transform.
    e.Graphics.TranslateTransform(100.0F, 0.0F)

    ' Draw translated, rotated ellipse to screen.
    e.Graphics.DrawEllipse(New Pen(Color.Blue, 3), 0, 0, 200, 80)
End Sub

下圖顯示執行上一個程式代碼範例的輸出。

已翻譯和轉換的橢圓

備註

原點通常是繪圖介面的左上角。 轉譯作業包含將轉換矩陣乘以其轉譯部分為 和 dy 參數的dx矩陣。 此方法會將轉譯矩陣前面加上轉換矩陣,以套用轉譯。

另請參閱

適用於