Share via


RectangleF.Union(RectangleF, RectangleF) Yöntem

Tanım

Birleşim oluşturan iki dikdörtgenin ikisini de içerebilen mümkün olan en küçük üçüncü dikdörtgeni oluşturur.

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

Parametreler

a
RectangleF

Birleşmesi için bir dikdörtgen.

b
RectangleF

Birleşmesi için bir dikdörtgen.

Döndürülenler

Birleşimi oluşturan iki dikdörtgenin ikisini de içeren üçüncü RectangleF bir yapı.

Örnekler

Bu örnek, Windows Forms ile kullanılmak üzere tasarlanmıştır ve e, bir OnPaint olay nesnesi gerektirirPaintEventArgs. Kod iki RectangleF s oluşturur ve bunları siyah ve kırmızı renkle ekrana çizer. Çizim amacıyla bunların s'ye Rectangle dönüştürülmesi gerektiğini fark edin. Ardından kod, yöntemini kullanarak Union üçüncü RectangleF bir oluşturur, bunu öğesine Rectangledönüştürür ve mavi renkle ekrana çizer. Üçüncü (mavi) dikdörtgenin, diğer iki dikdörtgenin ikisini de içerebilen mümkün olan en küçük dikdörtgen olduğuna dikkat edin:

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

Açıklamalar

İki dikdörtgenden biri boş olduğunda, yani tüm değerleri sıfır olduğunda, Union yöntem başlangıç noktası (0, 0) olan bir dikdörtgen ve boş olmayan dikdörtgenin yüksekliğini ve genişliğini döndürür. Örneğin, iki A = (0, 0; 0, 0) ve B = (1, 1; 2, 2) dikdörtgenleriniz varsa, A ve B'nin birleşimi (0, 0; 2, 2) olur.

Şunlara uygulanır