# Rectangle 构造函数

## 重载

 Rectangle(Point, Size) 用指定的位置和大小初始化 Rectangle 类的新实例。Initializes a new instance of the Rectangle class with the specified location and size. Rectangle(Int32, Int32, Int32, Int32) 用指定的位置和大小初始化 Rectangle 类的新实例。Initializes a new instance of the Rectangle class with the specified location and size.

## Rectangle(Point, Size)

``````public:
Rectangle(System::Drawing::Point location, System::Drawing::Size size);``````
``public Rectangle (System.Drawing.Point location, System.Drawing.Size size);``
``new System.Drawing.Rectangle : System.Drawing.Point * System.Drawing.Size -> System.Drawing.Rectangle``
``Public Sub New (location As Point, size As Size)``

#### 参数

location
Point

Point，它表示矩形区域的左上角。A Point that represents the upper-left corner of the rectangular region.

size
Size

Size，它表示矩形区域的宽度和高度。A Size that represents the width and height of the rectangular region.

## Rectangle(Int32, Int32, Int32, Int32)

``````public:
Rectangle(int x, int y, int width, int height);``````
``public Rectangle (int x, int y, int width, int height);``
``new System.Drawing.Rectangle : int * int * int * int -> System.Drawing.Rectangle``
``Public Sub New (x As Integer, y As Integer, width As Integer, height As Integer)``

x
Int32

y
Int32

width
Int32

height
Int32

### 示例

``````private:
void InstanceRectangleIntersection( PaintEventArgs^ e )
{
Rectangle rectangle1 = Rectangle(50,50,200,100);
Rectangle rectangle2 = Rectangle(70,20,100,200);
e->Graphics->DrawRectangle( Pens::Black, rectangle1 );
e->Graphics->DrawRectangle( Pens::Red, rectangle2 );
if ( rectangle1.IntersectsWith( rectangle2 ) )
{
rectangle1.Intersect( rectangle2 );
if (  !rectangle1.IsEmpty )
{
e->Graphics->FillRectangle( Brushes::Green, rectangle1 );
}
}
}
``````
``````private void InstanceRectangleIntersection(PaintEventArgs e)
{

Rectangle rectangle1 = new Rectangle(50, 50, 200, 100);
Rectangle rectangle2 = new Rectangle(70, 20, 100, 200);

e.Graphics.DrawRectangle(Pens.Black, rectangle1);
e.Graphics.DrawRectangle(Pens.Red, rectangle2);

if (rectangle1.IntersectsWith(rectangle2))
{
rectangle1.Intersect(rectangle2);
if (!rectangle1.IsEmpty)
{
e.Graphics.FillRectangle(Brushes.Green, rectangle1);
}
}
}
``````
``````  Private Sub InstanceRectangleIntersection( _
ByVal e As PaintEventArgs)

Dim rectangle1 As New Rectangle(50, 50, 200, 100)
Dim rectangle2 As New Rectangle(70, 20, 100, 200)

e.Graphics.DrawRectangle(Pens.Black, rectangle1)
e.Graphics.DrawRectangle(Pens.Red, rectangle2)

If (rectangle1.IntersectsWith(rectangle2)) Then
rectangle1.Intersect(rectangle2)
If Not (rectangle1.IsEmpty) Then
e.Graphics.FillRectangle(Brushes.Green, rectangle1)
End If
End If
End Sub
``````