Export (0) Print
Expand All

Graphics.ResetTransform Method

Resets the world transformation matrix of this Graphics object to the identity matrix.

[Visual Basic]
Public Sub ResetTransform()
[C#]
public void ResetTransform();
[C++]
public: void ResetTransform();
[JScript]
public function ResetTransform();

Return Value

This method does not return a value.

Remarks

The identity matrix represents a transformation with no scaling, rotation, or translation. Resetting the world transformation of this Graphics object to the identity matrix means that its world transformation doesn't change the geometry of transformed items.

Example

[Visual Basic, C#] The following 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 actionts:

  • Translates the world transform of the Windows form by a vector (100, 0).
  • Saves the graphics state of the form.
  • Resets the world transform of the form to an identity and fills a rectangle with a solid red brush.
  • Restores the translated graphics state and fills a rectangle with a solid blue brush.

[Visual Basic, C#] The result is an untranslated red-filled rectangle and a translated blue-filled rectangle.

[Visual Basic] 
Public Sub SaveRestore(e As PaintEventArgs)
' Translate transformation matrix.
e.Graphics.TranslateTransform(100, 0)
' Save translated graphics state.
Dim transState As GraphicsState = e.Graphics.Save()
' Reset transformation matrix to identity and fill rectangle.
e.Graphics.ResetTransform()
e.Graphics.FillRectangle(New SolidBrush(Color.Red), 0, 0, 100, 100)
' Restore graphics state to translated state and fill second
' rectangle.
e.Graphics.Restore(transState)
e.Graphics.FillRectangle(New SolidBrush(Color.Blue), 0, 0, _
100, 100)
End Sub
        
[C#] 
public void SaveRestore(PaintEventArgs e)
{
// Translate transformation matrix.
e.Graphics.TranslateTransform(100, 0);
// Save translated graphics state.
GraphicsState transState = e.Graphics.Save();
// Reset transformation matrix to identity and fill rectangle.
e.Graphics.ResetTransform();
e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 100, 100);
// Restore graphics state to translated state and fill second rectangle.
e.Graphics.Restore(transState);
e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 100, 100);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Graphics Class | Graphics Members | System.Drawing Namespace

Show:
© 2014 Microsoft