Information
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.Intersect(Rect&, const Rect&, const Rect&) method

Applies to: desktop apps only

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

Syntax

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

Parameters

c [out]

Type: Rect&

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

a [in]

Type: const Rect&

Reference to one of the two rectangles to be intersected.

b [in]

Type: const Rect&

Reference to one of the two rectangles to be intersected.

Return value

Type:

Type: BOOL

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

Examples

The following example creates three Rect objects, draws the first two rectangles, and then draws the third rectangle that indicates the intersection of the first two rectangles.


VOID Example_IntersectABC(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;

   // 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);

   // Draw the rectangle that indicates the intersection of the two rectangles.
   if(rectC.Intersect(rectC, rectA, rectB))
   {
      // rectC is not empty.
      // Draw the intersection with a thick green pen.
      pGreenPen = new Pen(Color(255, 0, 255, 0), 7);
     graphics.DrawRectangle(pGreenPen, rectC);
   }
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplustypes.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

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

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

Show:
© 2015 Microsoft