Rectangle.Union(Rectangle, Rectangle) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
public:
static System::Drawing::Rectangle Union(System::Drawing::Rectangle a, System::Drawing::Rectangle b);
public static System.Drawing.Rectangle Union(System.Drawing.Rectangle a, System.Drawing.Rectangle b);
static member Union : System.Drawing.Rectangle * System.Drawing.Rectangle -> System.Drawing.Rectangle
Public Shared Function Union (a As Rectangle, b As Rectangle) As Rectangle
Parametry
Obdélník, který se má sjednocovat.
Obdélník, který se má sjednocovat.
Návraty
Struktura Rectangle , která ohraničuje sjednocení dvou Rectangle struktur.
Příklady
Následující příklad kódu ukazuje, jak použít metodu Union . Tento příklad je určený pro použití s formulářem Windows. Vložte tento kód do formuláře a zavolejte metodu ShowRectangleUnion při zpracování události formuláře Paint a předejte e jako PaintEventArgs.
private:
void ShowRectangleUnion( PaintEventArgs^ e )
{
// Declare two rectangles and draw them.
Rectangle rectangle1 = Rectangle(30,40,50,100);
Rectangle rectangle2 = Rectangle(50,60,100,60);
e->Graphics->DrawRectangle( Pens::Sienna, rectangle1 );
e->Graphics->DrawRectangle( Pens::BlueViolet, rectangle2 );
// Declare a third rectangle as a union of the first two.
Rectangle rectangle3 = Rectangle::Union( rectangle1, rectangle2 );
// Fill in the third rectangle in a semi-transparent color.
Color transparentColor = Color::FromArgb( 40, 135, 135, 255 );
e->Graphics->FillRectangle( gcnew SolidBrush( transparentColor ), rectangle3 );
}
private void ShowRectangleUnion(PaintEventArgs e)
{
// Declare two rectangles and draw them.
Rectangle rectangle1 = new Rectangle(30, 40, 50, 100);
Rectangle rectangle2 = new Rectangle(50, 60, 100, 60);
e.Graphics.DrawRectangle(Pens.Sienna, rectangle1);
e.Graphics.DrawRectangle(Pens.BlueViolet, rectangle2);
// Declare a third rectangle as a union of the first two.
Rectangle rectangle3 = Rectangle.Union(rectangle1, rectangle2);
// Fill in the third rectangle in a semi-transparent color.
Color transparentColor = Color.FromArgb(40, 135, 135, 255);
e.Graphics.FillRectangle(new SolidBrush(transparentColor), rectangle3);
}
Private Sub ShowRectangleUnion(ByVal e As PaintEventArgs)
' Declare two rectangles and draw them.
Dim rectangle1 As New Rectangle(30, 40, 50, 100)
Dim rectangle2 As New Rectangle(50, 60, 100, 60)
e.Graphics.DrawRectangle(Pens.Sienna, rectangle1)
e.Graphics.DrawRectangle(Pens.BlueViolet, rectangle2)
' Declare a third rectangle as a union of the first two.
Dim rectangle3 As Rectangle = Rectangle.Union(rectangle1, _
rectangle2)
' Fill in the third rectangle in a semi-transparent color.
Dim transparentColor As Color = Color.FromArgb(40, 135, 135, 255)
e.Graphics.FillRectangle(New SolidBrush(transparentColor), _
rectangle3)
End Sub
Poznámky
Pokud je jeden ze dvou obdélníků prázdný, což znamená, že všechny jeho hodnoty jsou nula, Union metoda vrátí 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).