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
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
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 参数。 此方法通过将转换矩阵前面追加到转换矩阵来应用翻译。

另请参阅

适用于