Region.GetBounds(Rect*, const Graphics*) method

Applies to: desktop apps only

The Region::GetBounds method gets a rectangle that encloses this region.

Syntax

Status GetBounds(
  [out]  Rect *rect,
  [in]   const Graphics *g
) const;

Parameters

  • rect [out]
    Type: Rect*

    Pointer to a Rect object that receives the enclosing rectangle.

  • g [in]
    Type: const Graphics*

    Pointer to a Graphics object that contains the world and page transformations required to calculate the device coordinates of this region and the rectangle.

Return value

Type:

Type: Status****

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Remarks

The current world and page transformations of the graphics object are used to calculate the region and the rectangle as they are drawn on the display device. The rectangle returned by Region::GetBounds is not always the smallest possible rectangle.

Examples

The following example creates a region from a path, gets the region's enclosing rectangle, and then displays both.

VOID Example_GetBoundsRect(HDC hdc)
{
   Graphics graphics(hdc);

   Point points[] = {
      Point(110, 20),
      Point(120, 30),
      Point(100, 60),
      Point(120, 70),
      Point(150, 60),
      Point(140, 10)};

   GraphicsPath path;
    SolidBrush solidBrush(Color(255, 255, 0, 0));
    Pen pen(Color(255, 0, 0, 0));
    Rect rect;

   path.AddClosedCurve(points, 6);

    // Create a region from a path.
    Region pathRegion(&path);    
    
    // Get the region's enclosing rectangle.
    pathRegion.GetBounds(&rect, &graphics);

    // Show the region and the enclosing rectangle.
    graphics.FillRegion(&solidBrush, &pathRegion);
    graphics.DrawRectangle(&pen, rect);
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusheaders.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Region

GraphicsPath

Rect

Status

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012