RectangleF.Union(RectangleF, RectangleF) Método
Definição
Cria o menor terceiro retângulo possível que pode conter os dois retângulos que formam uma união.Creates the smallest possible third rectangle that can contain both of two rectangles that form a union.
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
Parâmetros
Um retângulo a se unir.A rectangle to union.
Um retângulo a se unir.A rectangle to union.
Retornos
Uma terceira estrutura RectangleF que contém os dois retângulos que formam a união.A third RectangleF structure that contains both of the two rectangles that form the union.
Exemplos
Este exemplo foi projetado para uso com Windows Forms, e ele requer PaintEventArgs e, um OnPaint objeto de evento.This example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. O código cria dois RectangleF s e os desenha na tela em preto e vermelho.The code creates two RectangleF s and draws them to the screen in black and red. Observe que eles precisam ser convertidos em Rectangle s para fins de desenho.Notice that they have to be converted to Rectangle s for drawing purposes. Em seguida, o código cria um terceiro RectangleF usando o Union método, converte-o em um Rectangle e o desenha na tela em azul.Then the code creates a third RectangleF using the Union method, converts it to a Rectangle, and draws it to the screen in blue. Observe que o terceiro retângulo (azul) é o menor retângulo possível que pode conter ambos os dois retângulos:Notice the third (blue) rectangle is the smallest possible rectangle that can contain both of the other two rectangles:
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
Comentários
Quando um dos dois retângulos está vazio, o que significa que todos os seus valores são zero, o Union método retorna um retângulo com um ponto inicial de (0, 0) e a altura e a largura do retângulo não vazio.When one of the two rectangles is empty, meaning all of its values are zero, the Union method returns a rectangle with a starting point of (0, 0), and the height and width of the non-empty rectangle. Por exemplo, se você tiver dois retângulos A = (0, 0; 0, 0) e B = (1, 1; 2, 2), a União de A e B será (0, 0; 2, 2).For example, if you have two rectangles A = (0, 0; 0, 0) and B = (1, 1; 2, 2), then the union of A and B is (0, 0; 2, 2).