Прочетете на английски Редактиране

Споделяне чрез


RectangleF.Intersect Method

Definition

Determines the RectangleF structure that represents the intersection of two rectangles.

Overloads

Intersect(RectangleF)

Replaces this RectangleF structure with the intersection of itself and the specified RectangleF structure.

Intersect(RectangleF, RectangleF)

Returns a RectangleF structure that represents the intersection of two rectangles. If there is no intersection, and empty RectangleF is returned.

Intersect(RectangleF)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

Replaces this RectangleF structure with the intersection of itself and the specified RectangleF structure.

C#
public void Intersect(System.Drawing.RectangleF rect);

Parameters

rect
RectangleF

The rectangle to intersect.

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Intersect(RectangleF, RectangleF)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

Returns a RectangleF structure that represents the intersection of two rectangles. If there is no intersection, and empty RectangleF is returned.

C#
public static System.Drawing.RectangleF Intersect(System.Drawing.RectangleF a, System.Drawing.RectangleF b);

Parameters

a
RectangleF

A rectangle to intersect.

b
RectangleF

A rectangle to intersect.

Returns

A third RectangleF structure the size of which represents the overlapped area of the two specified rectangles.

Examples

This example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code creates two RectangleF objects and draws them to the screen in black and red. Notice that they have to be converted to Rectangle objects for drawing purposes. Then the code creates a third RectangleF using the Intersect method, converts it to a Rectangle, and draws it to the screen in blue. Notice the third (blue) rectangle is the area of overlap of the other two rectangles:

C#
public void RectangleFIntersectExample(PaintEventArgs e)
{
             
    // Create two rectangles.
    RectangleF firstRectangleF = new RectangleF(0, 0, 75, 50);
    RectangleF secondRectangleF = new RectangleF(50, 20, 50, 50);
             
    // Convert the RectangleF structures to Rectangle structures and draw them to the
             
    // screen.
    Rectangle firstRect = Rectangle.Truncate(firstRectangleF);
    Rectangle secondRect = Rectangle.Truncate(secondRectangleF);
    e.Graphics.DrawRectangle(Pens.Black, firstRect);
    e.Graphics.DrawRectangle(Pens.Red, secondRect);
             
    // Get the intersection.
    RectangleF intersectRectangleF =
        RectangleF.Intersect(firstRectangleF,
        secondRectangleF);
             
    // Draw the intersectRectangleF to the screen.
    Rectangle intersectRect =
        Rectangle.Truncate(intersectRectangleF);
    e.Graphics.DrawRectangle(Pens.Blue, intersectRect);
}

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1