Method function IGDIPlus.IGPGraphics.BeginContainerF(TGPRectF;TGPRectF;TGPUnit) : TGPGraphicsContainer

From Mitov Wiki Doc
Revision as of 17:19, 18 October 2012 by David Alm (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a Beta Read Only version of this page. Please review and send recommendations to We will enable the editing as soon as we are happy with the overall Wiki site.

Class: IGPGraphics




function BeginContainerF( dstrect : TGPRectF, srcrect : TGPRectF, unit_ : TGPUnit ) : TGPGraphicsContainer;

C++ Builder:

TGPGraphicsContainer __fastcall BeginContainerF( TGPRectF dstrect, TGPRectF srcrect, TGPUnit unit_ );

Visual C++ (MFC):

BeginContainerF(  dstrect,  srcrect,  unit_ );


Begins a new graphics container.


Call this method to begin a new graphics container.


The following example calls the BeginContainer method to create a graphics container. The code specifies a transformation for the container by passing two rectangles to the BeginContainer method. The code calls Graphics::FillEllipse twice: once inside the container and once outside the container (after the call to EndContainer).

  AGraphics : IGPGraphics;
  APath : IGPGraphicsPath;
  ABlackPen : IGPPen;
  AContainer : IGPGraphicsContainer;
  srcRect : TGPRectF;
  destRect : TGPRectF;

  AGraphics := TGPGraphics.Create( ACanvas );
  APath := TGPGraphicsPath.Create();

  // Define a translation and scale transformation for the container.
  srcRect := MakeRect(0.0, 0.0, 200.0, 100.0);
  destRect := MakeRect(100.0, 100.0, 200.0, 200.0);

  // Create a graphics container with a (100, 100) translation
  // and (1, 2) scale.
  AContainer := graphics.BeginContainerF(destRect, srcRect, UnitPixel);

  // Fill an ellipse in the container.
  graphics.FillEllipse( TGPSolidBrush( aclRed ), 0, 0, 100, 60 );

  // End the container.

  // Fill the same ellipse outside the container.
  graphics.FillEllipse( TGPSolidBrush( aclBlue ), 0, 0, 100, 60 );

Remarks Use this method to create nested graphics containers. Graphics containers are used to retain graphics state, such as transformations, clipping regions, and various rendering properties.

The BeginContainer method returns a value of type GraphicsContainer. When you have finished using a container, pass that value to the EndContainer method. The GraphicsContainer data type is defined in Gdiplusenums.h.

The dstrect and srcrect parameters specify a transformation. It is the transformation that, when applied to srcrect, results in dstrect.

When you call the BeginContainer method of a Graphics object, an information block that holds the state of the Graphics object is put on a stack. The BeginContainer method returns a value that identifies that information block. When you pass the identifying value to the EndContainer method, the information block is removed from the stack and is used to restore the Graphics object to the state it was in at the time of the BeginContainer 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 an identifier for the information block. When you pass one of those identifiers to the EndContainer method, the Graphics object is returned to the state it was in at the time of the BeginContainer call that returned that particular identifier. The information block placed on the stack by that BeginContainer call is removed from the stack, and all information blocks placed on that stack after that BeginContainer 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 call is paired with a BeginContainer call, a Restore call is paired with a Save call.

Caution When you call EndContainer, all information blocks placed on the stack (by Save or by BeginContainer) after the corresponding call to BeginContainer are removed from the stack. Likewise, when you call Restore, all information blocks placed on the stack (by Save or by BeginContainer) after the corresponding call to Save are removed from the stack.

For more information about graphics containers, see "Nested Graphics Containers" on MSDN.

Personal tools