RectangleF.Union(RectangleF, RectangleF) Metoda

Definicja

Tworzy najmniejszy możliwy trzeci prostokąt, który może zawierać oba prostokąty, które tworzą unię.

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

Parametry

a
RectangleF

Prostokąt do połączenia.

b
RectangleF

Prostokąt do połączenia.

Zwraca

RectangleF

Trzecia RectangleF struktura zawierająca oba prostokąty, które tworzą unię.

Przykłady

Ten przykład jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgs e, OnPaint obiektu zdarzenia. Kod tworzy dwa RectangleF s i rysuje je na ekranie w kolorze czarnym i czerwonym. Zwróć uwagę, że muszą zostać przekonwertowane na Rectangle s na potrzeby rysowania. Następnie kod tworzy trzeci RectangleF przy użyciu Union metody , konwertuje go na Rectangleobiekt i rysuje go na ekran na niebiesko. Zwróć uwagę, że trzeci (niebieski) prostokąt jest najmniejszym możliwym prostokątem, który może zawierać oba pozostałe dwa prostokąty:

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

Uwagi

Gdy jeden z dwóch prostokątów jest pusty, co oznacza, że wszystkie jego wartości są zerowe, Union metoda zwraca prostokąt z punktem początkowym (0, 0), a wysokość i szerokość niepustego prostokąta. Jeśli na przykład masz dwa prostokąty A = (0, 0; 0, 0) i B = (1, 1; 2, 2), wówczas związek A i B to (0, 0; 2, 2).

Dotyczy