System.Drawing.Graphics.Save Method

Saves the current state of this System.Drawing.Graphics and identifies the saved state with a System.Drawing.Drawing2D.GraphicsState.

Syntax

public System.Drawing.Drawing2D.GraphicsState Save ()

Returns

This method returns a System.Drawing.Drawing2D.GraphicsState that represents the saved state of this System.Drawing.Graphics.

Remarks

When you call the Graphics.Save method of a System.Drawing.Graphics, an information block that holds the state of the System.Drawing.Graphics is put on a stack. The Graphics.Save method returns a System.Drawing.Drawing2D.GraphicsState that identifies that information block. When you pass the identifying System.Drawing.Drawing2D.GraphicsState to the Graphics.Restore(System.Drawing.Drawing2D.GraphicsState) method, the information block is removed from the stack and is used to restore the System.Drawing.Graphics to the state it was in at the time of the Graphics.Save method call. Note that the System.Drawing.Drawing2D.GraphicsState returned by a given call to the Graphics.Save method can be passed only once to the Graphics.Restore(System.Drawing.Drawing2D.GraphicsState) method.

Calls to the Graphics.Save method can be nested; that is, you can call the Graphics.Save method several times before you call the Graphics.Restore(System.Drawing.Drawing2D.GraphicsState) method. Each time you call the Graphics.Save method, an information block is put on the stack, and you receive a System.Drawing.Drawing2D.GraphicsState for the information block. When you pass one of those objects to the Graphics.Restore(System.Drawing.Drawing2D.GraphicsState) method, the System.Drawing.Graphics is returned to the state it was in at the time of the Graphics.Save method call that returned that particular System.Drawing.Drawing2D.GraphicsState. The information block placed on the stack by that Graphics.Save method call is removed from the stack, and all information blocks placed on that stack after that Graphics.Save method call are also removed.

Calls to the Graphics.BeginContainer method place information blocks on the same stack as calls to the Graphics.Save method. Just as a Graphics.Restore(System.Drawing.Drawing2D.GraphicsState) call is paired with a Graphics.Save call, a Graphics.EndContainer(System.Drawing.Drawing2D.GraphicsContainer) method call is paired with a Graphics.BeginContainer method call.

When you call the Graphics.Restore(System.Drawing.Drawing2D.GraphicsState) method, all information blocks placed on the stack (by the Graphics.Save method or by the Graphics.BeginContainer method) after the corresponding call to the Graphics.Save method are removed from the stack. Likewise, When you call the Graphics.EndContainer(System.Drawing.Drawing2D.GraphicsContainer) method, all information blocks placed on the stack (by the Graphics.Save method or by the Graphics.BeginContainer method) after the corresponding call to the Graphics.BeginContainer method are removed from the stack.

Requirements

Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0