Rect 建構函式

定義

初始化 Rect 結構的新執行個體。

多載

Rect(Size)

初始化 Rect 類別的新執行個體,這個執行個體是所指定的大小而且位在 (0,0)。

Rect(Point, Point)

初始化 Rect 結構的新執行個體,這個執行個體剛好可以包含兩個指定的點。

Rect(Point, Size)

初始化 Rect 結構的新執行個體,這個執行個體具有指定的左上角位置和指定的寬度及高度。

Rect(Point, Vector)

初始化 Rect 結構的新執行個體,這個執行個體剛好可以包含指定的點以及所指定點和所指定向量的總和。

Rect(Double, Double, Double, Double)

初始化 Rect 結構的新執行個體,這個執行個體具有指定的 X 座標、Y 座標、寬度和高度。

Rect(Size)

初始化 Rect 類別的新執行個體,這個執行個體是所指定的大小而且位在 (0,0)。

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)

參數

size
Size

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

指定矩形左上角之位置的點。

size
Size

Size 結構,指定矩形的高度和寬度。

範例

下列範例示範如何使用 建構函式建立新的 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

要位移 (Offset) 所指定點的數量。 產生的矩形剛好可以包含兩個點。

範例

下列範例示範如何使用 建構函式建立新的 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

矩形的高度。

例外狀況

width 是負值。

-或- height 是負值。

備註

下列範例示範如何使用 建構函式建立新的 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;
}

適用於