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 窗体一起使用。 将此代码粘贴到窗体中,并在处理表单ShowRectangleUnion的事件时调用Paint该方法,并传递e为 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
注解
当两个矩形中的一个为空,这意味着其所有值均为零时, Union 该方法返回一个起点为 (0, 0) 的矩形,以及非空矩形的高度和宽度。 例如,如果你有两个矩形:A = (0, 0; 0, 0) 和 B = (1, 1; 1; 2, 2),则 A 和 B 的联合为 (0, 0; 2, 2)。