Freigeben über


Rect.Intersect(const Rect&) method

Applies to: desktop apps only

The Rect::Intersect method replaces this rectangle with the intersection of itself and another rectangle.

Syntax

BOOL Intersect(
  [in]  const Rect& rect
);

Parameters

  • rect [in]
    Type: const Rect&

    Reference to a rectangle to intersect with this rectangle.

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_IntersectRect(HDC hdc)
{
   Graphics graphics(hdc);

   // Create two rect objects.
   Rect rect1(50, 50, 200, 100);
   Rect rect2(70, 20, 100, 200);

   // Draw rect1 and rect2 with a thin black pen.
   Pen blackPen(Color(255, 0, 0, 0), 1);
   graphics.DrawRectangle(&blackPen, rect1);
   graphics.DrawRectangle(&blackPen, rect2);

   // Form the intersection of rect1 and rect2, and store
   // the result in rect1.
   rect1.Intersect(rect2);

   // Draw the new rect1 with a thick green pen.
   Pen greenPen(Color(255, 0, 255, 0), 7);
   graphics.DrawRectangle(&greenPen, rect1);
}

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