Rectangle.Union(Rectangle, Rectangle) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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
參數
要聯集的矩形。
要聯集的矩形。
傳回
Rectangle 結構,限定兩個 Rectangle 結構的聯集下限。
範例
下列程式碼範例會示範如何使用 Union 方法。 此範例的設計目的是要與 Windows Form 搭配使用。 將此程式代碼貼到表單中,並在處理表單的事件時呼叫 ShowRectangleUnion
方法,並e
傳遞為 PaintEventArgs。Paint
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
備註
當兩個矩形的其中一個是空的,這表示其所有值都是零時, Union 此方法會傳回起點為 (0、0) 的矩形,以及非空白矩形的高度和寬度。 例如,如果您有兩個矩形:A = (0,0;0, 0) 和 B = (1, 1;2, 2) ,然後 A 和 B 的聯集 (0, 0;2,2) 。