Export (0) Print
Expand All

Rectangle.IntersectsWith Method

Determines if this rectangle intersects with rect.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

Public Function IntersectsWith ( _
	rect As Rectangle _
) As Boolean


Type: System.Drawing.Rectangle

The rectangle to test.

Return Value

Type: System.Boolean
This method returns true if there is any intersection, otherwise false.

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 Sub InstanceRectangleIntersection( _
    ByVal e As PaintEventArgs)

    Dim rectangle1 As New Rectangle(50, 50, 200, 100)
    Dim rectangle2 As New Rectangle(70, 20, 100, 200)

    e.Graphics.DrawRectangle(Pens.Black, rectangle1)
    e.Graphics.DrawRectangle(Pens.Red, rectangle2)

    If (rectangle1.IntersectsWith(rectangle2)) Then
        If Not (rectangle1.IsEmpty) Then
            e.Graphics.FillRectangle(Brushes.Green, rectangle1)
        End If 
    End If 
End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft