Rectangle.Union(Rectangle, Rectangle) Metod

Definition

Hämtar en Rectangle struktur som innehåller en union av två Rectangle strukturer.

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

Parametrar

a
Rectangle

En rektangel till union.

b
Rectangle

En rektangel till union.

Returer

En Rectangle struktur som begränsar de två Rectangle strukturernas union.

Exempel

I följande kodexempel visas hur du använder Union metoden. Det här exemplet är utformat för användning med ett Windows formulär. Klistra in den här koden i ett formulär och anropa ShowRectangleUnion metoden när du hanterar formulärets Paint händelse och skicka e som PaintEventArgs.

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

Kommentarer

När en av de två rektanglarna är tom, vilket innebär att alla dess värden är noll, Union returnerar metoden en rektangel med en startpunkt på (0, 0) och höjden och bredden på den icke-tomma rektangeln. Om du till exempel har två rektanglar: A = (0, 0; 0, 0) och B = (1, 1; 2, 2), är förbundet mellan A och B (0, 0; 2, 2).

Gäller för