Rectangle.Union(Rectangle, Rectangle) Methode

Definition

Ruft eine Rectangle Struktur ab, die die Vereinigung zweier Rectangle Strukturen enthält.

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

Parameter

a
Rectangle

Ein Rechteck zur Vereinigung.

b
Rectangle

Ein Rechteck zur Vereinigung.

Gibt zurück

Eine Rectangle Struktur, die die Vereinigung der beiden Rectangle Strukturen begrenzt.

Beispiele

Im folgenden Codebeispiel wird die Verwendung der Union Methode veranschaulicht. Dieses Beispiel wurde für die Verwendung mit einem Windows Formular entwickelt. Fügen Sie diesen Code in ein Formular ein, und rufen Sie die ShowRectangleUnion Methode beim Behandeln des Formularereignisses Paint auf und übergeben als ePaintEventArgs.

private:
   void ShowRectangleUnion( PaintEventArgs^ e )
   {
      // Declare two rectangles and draw them.
      Rectangle rectangle1 = Rectangle(30,40,50,100);
      Rectangle rectangle2 = Rectangle(50,60,100,60);
      e->Graphics->DrawRectangle( Pens::Sienna, rectangle1 );
      e->Graphics->DrawRectangle( Pens::BlueViolet, rectangle2 );

      // Declare a third rectangle as a union of the first two.
      Rectangle rectangle3 = Rectangle::Union( rectangle1, rectangle2 );

      // Fill in the third rectangle in a semi-transparent color.
      Color transparentColor = Color::FromArgb( 40, 135, 135, 255 );
      e->Graphics->FillRectangle( gcnew SolidBrush( transparentColor ), rectangle3 );
   }
private void ShowRectangleUnion(PaintEventArgs e)
{

    // Declare two rectangles and draw them.
    Rectangle rectangle1 = new Rectangle(30, 40, 50, 100);
    Rectangle rectangle2 = new Rectangle(50, 60, 100, 60);
    e.Graphics.DrawRectangle(Pens.Sienna, rectangle1);
    e.Graphics.DrawRectangle(Pens.BlueViolet, rectangle2);

    // Declare a third rectangle as a union of the first two.
    Rectangle rectangle3 = Rectangle.Union(rectangle1, rectangle2);

    // Fill in the third rectangle in a semi-transparent color.
    Color transparentColor = Color.FromArgb(40, 135, 135, 255);
    e.Graphics.FillRectangle(new SolidBrush(transparentColor), rectangle3);
}
Private Sub ShowRectangleUnion(ByVal e As PaintEventArgs)

    ' Declare two rectangles and draw them.
    Dim rectangle1 As New Rectangle(30, 40, 50, 100)
    Dim rectangle2 As New Rectangle(50, 60, 100, 60)
    e.Graphics.DrawRectangle(Pens.Sienna, rectangle1)
    e.Graphics.DrawRectangle(Pens.BlueViolet, rectangle2)

    ' Declare a third rectangle as a union of the first two.
    Dim rectangle3 As Rectangle = Rectangle.Union(rectangle1, _
        rectangle2)

    ' Fill in the third rectangle in a semi-transparent color.
    Dim transparentColor As Color = Color.FromArgb(40, 135, 135, 255)
    e.Graphics.FillRectangle(New SolidBrush(transparentColor), _
        rectangle3)
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 haben: A = (0, 0; 0, 0) und B = (1, 1; 2, 2), dann ist die Vereinigung von A und B (0, 0; 2, 2).

Gilt für: