語言

Rectangle 建構函式

定義

初始化一個以指定位置與大小的新類別實例 Rectangle

多載

名稱 Description
Rectangle(Point, Size)

初始化一個以指定位置與大小的新類別實例 Rectangle

Rectangle(Int32, Int32, Int32, Int32)

初始化一個以指定位置與大小的新類別實例 Rectangle

Rectangle(Point, Size)

來源:
Rectangle.cs
來源:
Rectangle.cs
來源:
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 A 代表矩形區域的左上角。

size
Size

A Size 代表矩形區域的寬度與高度。

適用於

Rectangle(Int32, Int32, Int32, Int32)

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

矩形的高度。

範例

以下程式碼範例展示了 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

適用於