Saves a graphics container with the current state of this System.Drawing.Graphics and opens and uses a new graphics container.
This method returns a System.Drawing.Drawing2D.GraphicsContainer that represents the state of this System.Drawing.Graphics at the time of the method call.
Use this method with the Graphics.EndContainer(System.Drawing.Drawing2D.GraphicsContainer) method to create nested graphics containers. Graphics containers retain graphics state, such as transformation, clipping region, and rendering properties.
When you call the Graphics.BeginContainer 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.BeginContainer method returns a System.Drawing.Drawing2D.GraphicsContainer that identifies that information block. When you pass the identifying object to the Graphics.EndContainer(System.Drawing.Drawing2D.GraphicsContainer) 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.BeginContainer method call.
Containers can be nested; that is, you can call the Graphics.BeginContainer method several times before you call the Graphics.EndContainer(System.Drawing.Drawing2D.GraphicsContainer) method. Each time you call the Graphics.BeginContainer method, an information block is put on the stack, and you receive a System.Drawing.Drawing2D.GraphicsContainer for the information block. When you pass one of those objects to the Graphics.EndContainer(System.Drawing.Drawing2D.GraphicsContainer) method, the System.Drawing.Graphics is returned to the state it was in at the time of the Graphics.BeginContainer method call that returned that particular System.Drawing.Drawing2D.GraphicsContainer. The information block placed on the stack by that Graphics.BeginContainer method call is removed from the stack, and all information blocks placed on that stack after that Graphics.BeginContainer method call are also removed.
Calls to the Graphics.Save method place information blocks on the same stack as calls to the Graphics.BeginContainer method. Just as an Graphics.EndContainer(System.Drawing.Drawing2D.GraphicsContainer) method call is paired with a Graphics.BeginContainer method call, a Graphics.Restore(System.Drawing.Drawing2D.GraphicsState) method call is paired with a Graphics.Save method call.
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. Likewise, 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.
The graphics state established by the Graphics.BeginContainer method includes the rendering qualities of the default graphics state; any rendering-quality state changes existing when the method is called are reset to the default values.