Rectangle 建構函式

定義

使用指定的位置和大小,初始化 Rectangle 類別的新執行個體。

多載

Rectangle(Point, Size)

使用指定的位置和大小,初始化 Rectangle 類別的新執行個體。

Rectangle(Int32, Int32, Int32, Int32)

使用指定的位置和大小,初始化 Rectangle 類別的新執行個體。

Rectangle(Point, Size)

來源:
Rectangle.cs
來源:
Rectangle.cs
來源:
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)

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

矩形的高度。

範例

下列程式代碼範例示範RectangleIntersectIsEmpty、 和 IntersectsWith 成員。 此範例應該與 Windows Form 搭配使用。 將此程式代碼貼到表單中,並在處理表單的事件 Paint 時呼叫此方法,並 e 傳遞為 PaintEventArgs

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

適用於