Rectangle::Intersect Method (Rectangle, Rectangle)
.NET Framework (current version)
Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. If there is no intersection, an empty Rectangle is returned.
Assembly: System.Drawing (in System.Drawing.dll)
Parameters
- a
-
Type:
System.Drawing::Rectangle
A rectangle to intersect.
- b
-
Type:
System.Drawing::Rectangle
A rectangle to intersect.
Return Value
Type: System.Drawing::RectangleA Rectangle that represents the intersection of a and b.
The following code example demonstrates the Intersect, IsEmpty and the IntersectsWith members. This example should be used with a Windows Form. Paste this code into a form and call this method when handling the form's Paint event, passing e as PaintEventArgs.
private: void StaticRectangleIntersection( PaintEventArgs^ e ) { Rectangle rectangle1 = Rectangle(50,50,200,100); Rectangle rectangle2 = Rectangle(70,20,100,200); e->Graphics->DrawRectangle( Pens::Black, rectangle1 ); e->Graphics->DrawRectangle( Pens::Red, rectangle2 ); if ( rectangle1.IntersectsWith( rectangle2 ) ) { Rectangle rectangle3 = Rectangle::Intersect( rectangle1, rectangle2 ); if ( !rectangle3.IsEmpty ) { e->Graphics->FillRectangle( Brushes::Green, rectangle3 ); } } }
.NET Framework
Available since 1.1
Available since 1.1
Show: