Share via


RectangleF.Union(RectangleF, RectangleF) Metoda

Definice

Vytvoří nejmenší možný třetí obdélník, který může obsahovat oba dva obdélníky, které tvoří sjednocení.

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

Obdélník, který se má sjednocovat.

b
RectangleF

Obdélník, který se má sjednocovat.

Návraty

Třetí RectangleF struktura, která obsahuje oba dva obdélníky, které tvoří sjednocení.

Příklady

Tento příklad je určený pro použití s model Windows Forms a vyžaduje PaintEventArgs e, OnPaint objekt události. Kód vytvoří dvě RectangleF s a nakreslí je na obrazovku černou a červenou barvou. Všimněte si, že je nutné je převést na Rectangle s pro účely kreslení. Pak kód vytvoří třetí RectangleF metodu Union , převede ji na Rectanglea nakreslí ji na obrazovku modře. Všimněte si, že třetí (modrý) obdélník je nejmenší možný obdélník, který může obsahovat oba zbylých dvou obdélníků:

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

Poznámky

Pokud je jeden ze dvou obdélníků prázdný, což znamená, že všechny jeho hodnoty jsou nulové, Union vrátí metoda obdélník s počátečním bodem (0, 0) a výškou a šířkou neprázdného obdélníku. Pokud máte například dva obdélníky A = (0, 0; 0, 0) a B = (1, 1; 2, 2), pak sjednocení A a B je (0, 0; 2, 2).

Platí pro