Rectangle 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化一個以指定位置與大小的新類別實例 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)
參數
適用於
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
矩形的高度。
範例
以下程式碼範例展示了 Rectangle、 Intersect、 IsEmpty和 IntersectsWith 成員。 此範例應用於 Windows 表單。 將此程式碼貼入表單,並在處理表單 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