Rectangle 构造函数

定义

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

重载

名称 说明
Rectangle(Point, Size)

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

Rectangle(Int32, Int32, Int32, Int32)

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

Rectangle(Point, Size)

Source:
Rectangle.cs
Source:
Rectangle.cs
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
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

矩形的高度。

示例

下面的代码示例演示了Rectangle成员和IntersectIsEmptyIntersectsWith成员。 此示例应与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

适用于