RectangleF.Union(RectangleF, RectangleF) Methode

Definition

Erstellt das kleinste mögliche dritte Rechteck, das beide rechtecke enthalten kann, die eine Vereinigung bilden.

public:
 static System::Drawing::RectangleF Union(System::Drawing::RectangleF a, System::Drawing::RectangleF b);
public static System.Drawing.RectangleF Union(System.Drawing.RectangleF a, System.Drawing.RectangleF b);
static member Union : System.Drawing.RectangleF * System.Drawing.RectangleF -> System.Drawing.RectangleF
Public Shared Function Union (a As RectangleF, b As RectangleF) As RectangleF

Parameter

a
RectangleF

Ein Rechteck zur Vereinigung.

b
RectangleF

Ein Rechteck zur Vereinigung.

Gibt zurück

Eine dritte RectangleF Struktur, die beide Rechtecke enthält, die die Vereinigung bilden.

Beispiele

Dieses Beispiel wurde für die Verwendung mit Windows Forms entwickelt und erfordert PaintEventArgs e, ein OnPaint-Ereignisobjekt. Der Code erstellt zwei RectangleF s und zeichnet sie in Schwarz und Rot auf den Bildschirm. Beachten Sie, dass sie zu Zeichnungszwecken in s konvertiert Rectangle werden müssen. Anschließend erstellt der Code ein Drittes RectangleF mithilfe der Union Methode, konvertiert es in ein Rectangle, und zeichnet ihn in Blau auf den Bildschirm. Beachten Sie, dass das dritte (blaue) Rechteck das kleinste mögliche Rechteck ist, das beide der beiden anderen Rechtecke enthalten kann:

public:
   void RectangleFUnionExample( PaintEventArgs^ e )
   {
      // Create two rectangles and draw them to the screen.
      RectangleF firstRectangleF = RectangleF(0,0,75,50);
      RectangleF secondRectangleF = RectangleF(100,100,20,20);

      // 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 union rectangle.
      RectangleF unionRectangleF = RectangleF::Union( firstRectangleF, secondRectangleF );

      // Draw the unionRectangleF to the screen.
      Rectangle unionRect = Rectangle::Truncate( unionRectangleF );
      e->Graphics->DrawRectangle( Pens::Blue, unionRect );
   }
public void RectangleFUnionExample(PaintEventArgs e)
{
             
    // Create two rectangles and draw them to the screen.
    RectangleF firstRectangleF = new RectangleF(0, 0, 75, 50);
    RectangleF secondRectangleF = new RectangleF(100, 100, 20, 20);
             
    // 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 union rectangle.
    RectangleF unionRectangleF = RectangleF.Union(firstRectangleF,
        secondRectangleF);
             
    // Draw the unionRectangleF to the screen.
    Rectangle unionRect = Rectangle.Truncate(unionRectangleF);
    e.Graphics.DrawRectangle(Pens.Blue, unionRect);
}
Public Sub RectangleFUnionExample(ByVal e As PaintEventArgs)

    ' Create two rectangles and draw them to the screen.
    Dim firstRectangleF As New RectangleF(0, 0, 75, 50)
    Dim secondRectangleF As New RectangleF(100, 100, 20, 20)

    ' Convert the RectangleF structures to Rectangle structures and

    ' draw them to the screen.
    Dim firstRect As Rectangle = Rectangle.Truncate(firstRectangleF)
    Dim secondRect As Rectangle = Rectangle.Truncate(secondRectangleF)
    e.Graphics.DrawRectangle(Pens.Black, firstRect)
    e.Graphics.DrawRectangle(Pens.Red, secondRect)

    ' Get the union rectangle.
    Dim unionRectangleF As RectangleF = _
    RectangleF.Union(firstRectangleF, secondRectangleF)

    ' Draw the unionRectangleF to the screen.
    Dim unionRect As Rectangle = Rectangle.Truncate(unionRectangleF)
    e.Graphics.DrawRectangle(Pens.Blue, unionRect)
End Sub

Hinweise

Wenn eines der beiden Rechtecke leer ist, was bedeutet, dass alle Werte null sind, gibt die Union Methode ein Rechteck mit einem Startpunkt von (0, 0) und der Höhe und Breite des nicht leeren Rechtecks zurück. Wenn Sie beispielsweise zwei Rechtecke A = (0, 0; 0, 0) und B = (1, 1; 2, 2) haben, dann ist die Vereinigung von A und B (0, 0; 2, 2).

Gilt für: