Graphics.TranslateTransform 方法

定义

通过使此 Graphics 的转换矩阵左乘指定的平移来更改坐标系统的原点。

重载

TranslateTransform(Single, Single, MatrixOrder)

通过以指定顺序将指定平移应用于此 Graphics 的转换矩阵来更改坐标系统的原点。

TranslateTransform(Single, Single)

通过使此 Graphics 的转换矩阵左乘指定的平移来更改坐标系统的原点。

TranslateTransform(Single, Single, MatrixOrder)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
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 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 将 Windows 窗体的世界转换矩阵旋转 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

注解

转换操作包括将转换矩阵乘以其转换部分为 dxdy 参数的矩阵。 此方法根据 order 参数通过转换矩阵Graphics在 前面追加或追加转换矩阵。

另请参阅

适用于

TranslateTransform(Single, Single)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
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 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 将 Windows 窗体的世界转换矩阵旋转 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

下图显示了运行上一个代码示例的输出。

已转换和转换的椭圆

注解

原点通常是绘图图面的左上角。 转换操作包括将转换矩阵乘以其转换部分为 dxdy 参数的矩阵。 此方法通过将转换矩阵前面追加到转换矩阵来应用转换。

另请参阅

适用于