Graphics.TranslateTransform Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Changes the origin of the coordinate system by prepending the specified translation to the transformation matrix of this Graphics.
Overloads
TranslateTransform(Single, Single) |
Changes the origin of the coordinate system by prepending the specified translation to the transformation matrix of this Graphics. |
TranslateTransform(Single, Single, MatrixOrder) |
Changes the origin of the coordinate system by applying the specified translation to the transformation matrix of this Graphics in the specified order. |
TranslateTransform(Single, Single)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Changes the origin of the coordinate system by prepending the specified translation to the transformation matrix of this 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)
Parameters
- dx
- Single
The x-coordinate of the translation.
- dy
- Single
The y-coordinate of the translation.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Rotates the world transformation matrix of the Windows Form by 30.0F degrees.
Moves the origin of the graphics object by calling TranslateTransform, prepending the translation to the transformation matrix.
Draws a translated, rotated ellipse with a blue pen.
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
The following illustration shows the output of running the previous code example.
Remarks
The origin is typically the upper-left-hand corner of the drawing surface. The translation operation consists of multiplying the transformation matrix by a matrix whose translation part is the dx
and dy
parameters. This method applies the translation by prepending the translation matrix to the transformation matrix.
See also
Applies to
TranslateTransform(Single, Single, MatrixOrder)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Changes the origin of the coordinate system by applying the specified translation to the transformation matrix of this Graphics in the specified order.
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)
Parameters
- dx
- Single
The x-coordinate of the translation.
- dy
- Single
The y-coordinate of the translation.
- order
- MatrixOrder
Member of the MatrixOrder enumeration that specifies whether the translation is prepended or appended to the transformation matrix.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Rotates the world transformation matrix of the Windows Form by 30.0F degrees.
Moves the graphics object's origin by calling TranslateTransform, appending the translation to the world transformation matrix.
Draws a rotated, translated ellipse with a blue pen.
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
Remarks
The translation operation consists of multiplying the transformation matrix by a matrix whose translation part is the dx
and dy
parameters. This method prepends or appends the transformation matrix of the Graphics by the translation matrix according to the order
parameter.