Graphics.BeginContainer Method (RectangleF, RectangleF, GraphicsUnit)
Saves a graphics container with the current state of this Graphics and opens and uses a new graphics container with the specified scale transformation.
Assembly: System.Drawing (in System.Drawing.dll)
member BeginContainer : dstrect:RectangleF * srcrect:RectangleF * unit:GraphicsUnit -> GraphicsContainer
- Type: System.Drawing.RectangleF
RectangleF structure that, together with the srcrect parameter, specifies a scale transformation for the new graphics container.
- Type: System.Drawing.RectangleF
RectangleF structure that, together with the dstrect parameter, specifies a scale transformation for the new graphics container.
Use this method with the EndContainer method to create nested graphics containers. Graphics containers retain graphics state, such as transformation, clipping region, and rendering properties.
When you call the BeginContainer method of a Graphics, an information block that holds the state of the Graphics is put on a stack. The BeginContainer method returns a GraphicsContainer that identifies that information block. When you pass the identifying object to the EndContainer method, the information block is removed from the stack and is used to restore the Graphics to the state it was in at the time of the BeginContainer method call.
Containers can be nested; that is, you can call the BeginContainer method several times before you call the EndContainer method. Each time you call the BeginContainer method, an information block is put on the stack, and you receive a GraphicsContainer for the information block. When you pass one of those objects to the EndContainer method, the Graphics is returned to the state it was in at the time of the BeginContainer method call that returned that particular GraphicsContainer. The information block placed on the stack by that BeginContainer method call is removed from the stack, and all information blocks placed on that stack after that BeginContainer method call are also removed.
Calls to the Save method place information blocks on the same stack as calls to the BeginContainer method. Just as an EndContainer method call is paired with a BeginContainer method call, a Restore method call is paired with a Save method call.
When you call the EndContainer method, all information blocks placed on the stack (by the Save method or by the BeginContainer method) after the corresponding call to the BeginContainer method are removed from the stack. Likewise, when you call the Restore method, all information blocks placed on the stack (by the Save method or by the BeginContainer method) after the corresponding call to the Save method are removed from the stack.
This method specifies a scale transformation for the new graphics container with the dstrect and srcrect parameters. The scale is equal to the transformation that, when applied to srcrect, results in dstrect.
The graphics state established by the 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.
Creates two rectangles to specify a scale transformation for the new container.
Opens the new graphics container and saves the old container.
Fills a red rectangle in the (scaled coordinates of the) new container.
Closes the new container and restores the saved container.
Fills a green rectangle (to the unscaled coordinates) of the saved container.
The result is a green rectangle that overlies a smaller red rectangle.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.