RectF::Union method (gdiplustypes.h)

The RectF::Union method determines the union of two rectangles and stores the result in a RectF object.

Syntax

BOOL Union(
  [out] RectF &       c,
  [in]  const RectF & a,
  [in]  const RectF & b
);

Parameters

[out] c

Type: RectF&

Reference to a RectF object that receives the union of the two rectangles.

[in] a

Type: const RectF&

Reference to one of the two rectangles used to form the union.

[in] b

Type: const RectF&

Reference to one of the two rectangles used to form the union.

Return value

Type: BOOL

If the union of two rectangles is not empty, this method returns TRUE; otherwise, it returns FALSE.

Remarks

In GDI+, the union of two rectangles is the smallest rectangle that encloses the two rectangles. A rectangle is defined as empty if its width or height is less than or equal to zero.

Examples

The following example creates three rectangles. The code forms the union of the first two rectangles and stores the result in the third rectangle. The code determines whether the union is nonempty and, if so, draws the union.

VOID Example_UnionABC(HDC hdc)
{
   Graphics graphics(hdc);
   Pen* pGreenPen;

   // Create three RectF objects.
   RectF rectA(50, 50, 200, 100);
   RectF rectB(70, 20, 100, 200);
   RectF rectC;

   // Determine the union of rectA and rectB, and store the result in rectC.
   if(rectC.Union(rectC, rectA, rectB))
   {
      // rectC is not empty.
      // Draw the union with a thick green pen.
      pGreenPen = new Pen(Color(255, 0, 255, 0), 7);
      graphics.DrawRectangle(pGreenPen, rectC);
      delete pGreenPen;
   }
   // Draw rectA and rectB with a thin black pen.
   Pen blackPen(Color(255, 0, 0, 0), 1);
   graphics.DrawRectangle(&blackPen, rectA);
   graphics.DrawRectangle(&blackPen, rectB);}

Requirements

Requirement Value
Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdiplustypes.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See also

Intersect Methods

Pens, Lines, and Rectangles

Rect

RectF

Using a Pen to Draw Lines and Rectangles