RectangleF.Union(RectangleF, RectangleF) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee maakt u de kleinste mogelijke derde rechthoek die beide rechthoeken kan bevatten die een samenvoeging vormen.
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
Parameters
Een rechthoek met samenvoeging.
Een rechthoek met samenvoeging.
Retouren
Een derde RectangleF structuur die beide rechthoeken bevat die de samenvoeging vormen.
Voorbeelden
Dit voorbeeld is ontworpen voor gebruik met Windows Forms en vereist PaintEventArgs e, een OnPaint gebeurtenisobject. De code maakt twee RectangleF s en tekent deze in zwart en rood op het scherm. U ziet dat ze moeten worden geconverteerd naar Rectangle s voor tekendoeleinden. Vervolgens maakt de code een derde RectangleF met behulp van de Union methode, converteert deze naar een Rectangleen tekent deze naar het scherm in blauw. U ziet dat de derde (blauwe) rechthoek de kleinste mogelijke rechthoek is die beide andere twee rechthoeken kan bevatten:
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
Opmerkingen
Wanneer een van de twee rechthoeken leeg is, wat betekent dat alle waarden nul zijn, retourneert de Union methode een rechthoek met een beginpunt (0, 0) en de hoogte en breedte van de niet-lege rechthoek. Als u bijvoorbeeld twee rechthoeken A = (0, 0; 0, 0) en B = (1, 1; 2, 2) hebt, is de samenvoeging van A en B (0, 0; 2, 2).