Rectangle 构造函数

定义

用指定的位置和大小初始化 Rectangle 类的新实例。

重载

Rectangle(Point, Size)

用指定的位置和大小初始化 Rectangle 类的新实例。

Rectangle(Int32, Int32, Int32, Int32)

用指定的位置和大小初始化 Rectangle 类的新实例。

Rectangle(Point, Size)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

用指定的位置和大小初始化 Rectangle 类的新实例。

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,它表示矩形区域的左上角。

size
Size

Size,它表示矩形区域的宽度和高度。

适用于

Rectangle(Int32, Int32, Int32, Int32)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

用指定的位置和大小初始化 Rectangle 类的新实例。

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

矩形左上角的 x 坐标。

y
Int32

矩形左上角的 y 坐标。

width
Int32

矩形的宽度。

height
Int32

矩形的高度。

示例

下面的代码示例演示了 RectangleIntersectIsEmptyIntersectsWith 成员。 此示例应与 Windows 窗体一起使用。 将此代码粘贴到窗体中,并在处理窗体 Paint 的事件时调用此方法,作为 ePaintEventArgs传递。

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

适用于