TranslateTransform Method (Single, Single)
Collapse the table of content
Expand the table of content

Graphics.TranslateTransform Method (Single, Single)

Changes the origin of the coordinate system by prepending the specified translation to the transformation matrix of this Graphics.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public void TranslateTransform(
	float dx,
	float dy


Type: System.Single
The x-coordinate of the translation.
Type: System.Single
The y-coordinate of the translation.

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.

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.

private void TranslateTransformAngle(PaintEventArgs e)

    // Set world transform of graphics object to rotate.

    // 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);

The following illustration shows the output of running the previous code example.

Translated and transformed ellipse

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2016 Microsoft