Rectangle.Union(Rectangle, Rectangle) Rectangle.Union(Rectangle, Rectangle) Rectangle.Union(Rectangle, Rectangle) Rectangle.Union(Rectangle, Rectangle) Method

Definição

Obtém uma estrutura Rectangle que contém a união de duas estruturas Rectangle.Gets a Rectangle structure that contains the union of two Rectangle structures.

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

Parâmetros

a
Rectangle Rectangle Rectangle Rectangle

Um retângulo a se unir.A rectangle to union.

b
Rectangle Rectangle Rectangle Rectangle

Um retângulo a se unir.A rectangle to union.

Retornos

Uma estrutura Rectangle que associa a união de duas estruturas Rectangle.A Rectangle structure that bounds the union of the two Rectangle structures.

Exemplos

O exemplo de código a seguir demonstra como usar Union o método.The following code example demonstrates how to use the Union method. Este exemplo foi projetado para uso com um Windows Form.This example is designed for use with a Windows Form. Cole esse código em um formulário e chame o ShowRectangleUnion método ao manipular o evento do Paint formulário, passando e como PaintEventArgs.Paste this code into a form and call the ShowRectangleUnion method when handling the form's Paint event, passing e as 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

Comentários

Quando um dos dois retângulos está vazio, o que significa que todos os seus valores são zero Union , o método retorna um retângulo com um ponto inicial de (0, 0) e a altura e a largura do retângulo não vazio.When one of the two rectangles is empty, meaning all of its values are zero, the Union method returns a rectangle with a starting point of (0, 0), and the height and width of the non-empty rectangle. Por exemplo, se você tiver dois retângulos: A = (0, 0; 0, 0) e B = (1, 1; 2, 2), em seguida, a União de A e B é (0, 0; 2, 2).For example, if you have two rectangles: A = (0, 0; 0, 0) and B = (1, 1; 2, 2), then the union of A and B is (0, 0; 2, 2).

Aplica-se a