RectangleF.Intersect Metodo

Definizione

Determina la struttura RectangleF che rappresenta l'intersezione di due rettangoli.

Overload

Intersect(RectangleF)

Sostituisce questa struttura RectangleF con l'intersezione di se stessa e la struttura RectangleF specificata.

Intersect(RectangleF, RectangleF)

Restituisce una struttura RectangleF che rappresenta l'intersezione di due rettangoli. Se non è presente alcuna intersezione e viene restituita RectangleF vuota.

Intersect(RectangleF)

Origine:
RectangleF.cs
Origine:
RectangleF.cs
Origine:
RectangleF.cs

Sostituisce questa struttura RectangleF con l'intersezione di se stessa e la struttura RectangleF specificata.

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

Parametri

rect
RectangleF

Rettangolo da intersecare.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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
.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)

Origine:
RectangleF.cs
Origine:
RectangleF.cs
Origine:
RectangleF.cs

Restituisce una struttura RectangleF che rappresenta l'intersezione di due rettangoli. Se non è presente alcuna intersezione e viene restituita RectangleF vuota.

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

Parametri

a
RectangleF

Rettangolo da intersecare.

b
RectangleF

Rettangolo da intersecare.

Restituisce

Un terzo RectangleF struttura la cui dimensione rappresenta l'area sovrapposta dei due rettangoli specificati.

Esempio

Questo esempio è progettato per l'uso con Windows Form e richiede PaintEventArgse, un oggetto evento OnPaint. Il codice crea due oggetti RectangleF e li disegna sullo schermo in rosso e nero. Si noti che devono essere convertiti in oggetti Rectangle a scopo di disegno. Il codice crea quindi un terzo RectangleF usando il metodo Intersect, lo converte in un Rectanglee lo disegna sullo schermo in blu. Si noti che il terzo rettangolo (blu) è l'area di sovrapposizione degli altri due rettangoli:

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

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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
.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