The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

# Rect.Union method

Applies to: desktop apps only

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

### Syntax

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

### Parameters

c [out]

Type: Rect&

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

a [in]

Type: const Rect&

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

b [in]

Type: const Rect&

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

### Return value

Type:

Type: BOOL

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

### Remarks

In Windows 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 Rect objects.
Rect rectA(50, 50, 200, 100);
Rect rectB(70, 20, 100, 200);
Rect 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

 Minimum supported client Windows XP, Windows 2000 Professional Windows 2000 Server GDI+ 1.0 Gdiplustypes.h (include Gdiplus.h) Gdiplus.lib Gdiplus.dll

Rect
Intersect Methods
RectF
Using a Pen to Draw Lines and Rectangles
Pens, Lines, and Rectangles