Freigeben über


RectangleF.Union-Methode

Erstellt das kleinstmögliche dritte Rechteck, das zwei Rechtecke enthalten kann, die eine Gesamtmenge bilden.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Shared Function Union ( _
    a As RectangleF, _
    b As RectangleF _
) As RectangleF
'Usage
Dim a As RectangleF
Dim b As RectangleF
Dim returnValue As RectangleF

returnValue = RectangleF.Union(a, b)
public static RectangleF Union (
    RectangleF a,
    RectangleF b
)
public:
static RectangleF Union (
    RectangleF a, 
    RectangleF b
)
public static RectangleF Union (
    RectangleF a, 
    RectangleF b
)
public static function Union (
    a : RectangleF, 
    b : RectangleF
) : RectangleF

Parameter

  • a
    Ein Rechteck, mit dem die Gesamtmenge gebildet werden soll.
  • b
    Ein Rechteck, mit dem die Gesamtmenge gebildet werden soll.

Rückgabewert

Eine dritte RectangleF-Struktur, die die beiden die Gesamtmenge bildenden Rechtecke enthält.

Beispiel

Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert ein OnPaint-Ereignisobjekt PaintEventArgs e. Der Code erstellt zwei RectangleF und zeichnet diese in schwarz und rot auf dem Bildschirm. Beachten Sie, dass sie zum Zeichnen jeweils in ein Rectangle konvertiert werden müssen. Anschließend wird ein drittes RectangleF mit der Union-Methode erstellt, in ein Rectangle konvertiert und in blau auf dem Bildschirm gezeichnet. Beachten Sie, dass das dritte (blaue) Rechteck das kleinstmögliche Rechteck ist, das die beiden anderen Rechtecke enthalten kann:

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
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:
   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.get_Graphics().DrawRectangle(Pens.get_Black(), firstRect);
    e.get_Graphics().DrawRectangle(Pens.get_Red(), secondRect);

    // Get the union rectangle.
    RectangleF unionRectangleF = RectangleF.Union(firstRectangleF,
        secondRectangleF);

    // Draw the unionRectangleF to the screen.
    Rectangle unionRect = Rectangle.Truncate(unionRectangleF);

    e.get_Graphics().DrawRectangle(Pens.get_Blue(), unionRect);
} //RectangleFUnionExample

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

RectangleF-Struktur
RectangleF-Member
System.Drawing-Namespace