Rect 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化結構的新實例 Rect 。
多載
| 名稱 | Description |
|---|---|
| Rect(Size) |
初始化一個大小符合指定大小且位於 (0,0) 的新結構實例 Rect 。 |
| Rect(Point, Point) |
初始化一個結構的新實例,該實例 Rect 恰好足夠大以包含指定的兩個點。 |
| Rect(Point, Size) |
初始化一個結構的新實例,該實例 Rect 具有指定的左上角位置,以及指定的寬度與高度。 |
| Rect(Point, Vector) |
初始化一個結構的新實例,該實例 Rect 恰好足夠大,能包含指定點、指定點與指定向量的總和。 |
| Rect(Double, Double, Double, Double) |
初始化一個結構的新實例,該實例 Rect 具有指定的 x 座標、y 座標、寬度和高度。 |
Rect(Size)
初始化一個大小符合指定大小且位於 (0,0) 的新結構實例 Rect 。
public:
Rect(System::Windows::Size size);
public Rect(System.Windows.Size size);
new System.Windows.Rect : System.Windows.Size -> System.Windows.Rect
Public Sub New (size As Size)
參數
範例
以下範例說明如何利用Rect建構子建立新Rect(Size)結構。
private Rect createRectExample2()
{
// This constructor initializes a new instance of the Rect structure that
// is of the specified size and is located at (0,0).
Rect myRectangle = new Rect(new Size(200, 50));
// Returns a rectangle with a width of 200, a height of 50 and a position
// of 0,0.
return myRectangle;
}
適用於
Rect(Point, Point)
初始化一個結構的新實例,該實例 Rect 恰好足夠大以包含指定的兩個點。
public:
Rect(System::Windows::Point point1, System::Windows::Point point2);
public Rect(System.Windows.Point point1, System.Windows.Point point2);
new System.Windows.Rect : System.Windows.Point * System.Windows.Point -> System.Windows.Rect
Public Sub New (point1 As Point, point2 As Point)
參數
- point1
- Point
新矩形必須包含的第一個點。
- point2
- Point
新矩形必須包含的第二點。
範例
以下範例說明如何利用Rect建構子建立新Rect(Point, Point)結構。
private Rect createRectExample3()
{
// This constructor intializes a new instance of the Rect structure that is
// exactly large enough to contain the two specified points.
Rect myRectangle = new Rect(new Point(15, 30), new Point(50,70));
// Returns a rectangle with a position of 15,30, a width of 35 and height of 40.
return myRectangle;
}
適用於
Rect(Point, Size)
初始化一個結構的新實例,該實例 Rect 具有指定的左上角位置,以及指定的寬度與高度。
public:
Rect(System::Windows::Point location, System::Windows::Size size);
public Rect(System.Windows.Point location, System.Windows.Size size);
new System.Windows.Rect : System.Windows.Point * System.Windows.Size -> System.Windows.Rect
Public Sub New (location As Point, size As Size)
參數
- location
- Point
一個點,指定矩形左上角的位置。
範例
以下範例說明如何利用Rect建構子建立新Rect(Point, Size)結構。
private Rect createRectExample4()
{
// This constructor initializes a new instance of the Rect structure that has the
// specified top-left corner location and the specified width and height (Size).
Rect myRectangle = new Rect(new Point(15, 30), new Size(35, 40));
// Returns a rectangle with a position of 15,30, a width of 35 and height of 40.
return myRectangle;
}
適用於
Rect(Point, Vector)
初始化一個結構的新實例,該實例 Rect 恰好足夠大,能包含指定點、指定點與指定向量的總和。
public:
Rect(System::Windows::Point point, System::Windows::Vector vector);
public Rect(System.Windows.Point point, System.Windows.Vector vector);
new System.Windows.Rect : System.Windows.Point * System.Windows.Vector -> System.Windows.Rect
Public Sub New (point As Point, vector As Vector)
參數
- point
- Point
矩形必須包含的第一個點。
- vector
- Vector
抵消指定點的金額。 所得的長方形將恰好足夠容納兩個點。
範例
以下範例說明如何利用Rect建構子建立新Rect(Point, Vector)結構。
private Rect createRectExample5()
{
// This constructor Intializes a new instance of the Rect structure that is exactly
// large enough to contain the specified point and the sum of the specified point
// and the specified vector.
Rect myRectangle = new Rect(new Point(15, 30), new Vector(35, 40));
// Returns a rectangle with a position of 15,30, a width of 35 and height of 40.
return myRectangle;
}
適用於
Rect(Double, Double, Double, Double)
初始化一個結構的新實例,該實例 Rect 具有指定的 x 座標、y 座標、寬度和高度。
public:
Rect(double x, double y, double width, double height);
public Rect(double x, double y, double width, double height);
new System.Windows.Rect : double * double * double * double -> System.Windows.Rect
Public Sub New (x As Double, y As Double, width As Double, height As Double)
參數
- x
- Double
矩形左上角的 x 座標。
- y
- Double
矩形左上角的 y 座標。
- width
- Double
長方形的寬度。
- height
- Double
矩形的高度。
例外狀況
備註
以下範例說明如何利用Rect建構子建立新Rect(Double, Double, Double, Double)結構。
private Rect createRectExample6()
{
// This constructor intializes a new instance of the Rect structure with the specified
// x- and y-coordinates and the specified width and height.
Rect myRectangle = new Rect(15, 30, 35, 40);
// Returns a rectangle with a position of 15,30, a width of 35 and height of 40.
return myRectangle;
}