Modifier

Partager via


Rect Constructors

Definition

Initializes a new instance of the Rect structure.

Overloads

Rect(Size)

Initializes a new instance of the Rect structure that is of the specified size and is located at (0,0).

Rect(Point, Point)

Initializes a new instance of the Rect structure that is exactly large enough to contain the two specified points.

Rect(Point, Size)

Initializes a new instance of the Rect structure that has the specified top-left corner location and the specified width and height.

Rect(Point, Vector)

Initializes 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(Double, Double, Double, Double)

Initializes a new instance of the Rect structure that has the specified x-coordinate, y-coordinate, width, and height.

Rect(Size)

Initializes a new instance of the Rect structure that is of the specified size and is located at (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)

Parameters

size
Size

A Size structure that specifies the width and height of the rectangle.

Examples

The following example shows how to create a new Rect structure by using the Rect(Size) constructor.

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;
}

Applies to

Rect(Point, Point)

Initializes a new instance of the Rect structure that is exactly large enough to contain the two specified points.

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)

Parameters

point1
Point

The first point that the new rectangle must contain.

point2
Point

The second point that the new rectangle must contain.

Examples

The following example shows how to create a new Rect structure by using the Rect(Point, Point) constructor.

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;
}

Applies to

Rect(Point, Size)

Initializes a new instance of the Rect structure that has the specified top-left corner location and the specified width and height.

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)

Parameters

location
Point

A point that specifies the location of the top-left corner of the rectangle.

size
Size

A Size structure that specifies the width and height of the rectangle.

Examples

The following example shows how to create a new Rect structure by using the Rect(Point, Size) constructor.

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;
}

Applies to

Rect(Point, Vector)

Initializes 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.

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)

Parameters

point
Point

The first point the rectangle must contain.

vector
Vector

The amount to offset the specified point. The resulting rectangle will be exactly large enough to contain both points.

Examples

The following example shows how to create a new Rect structure by using the Rect(Point, Vector) constructor.

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;
}

Applies to

Rect(Double, Double, Double, Double)

Initializes a new instance of the Rect structure that has the specified x-coordinate, y-coordinate, width, and height.

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)

Parameters

x
Double

The x-coordinate of the top-left corner of the rectangle.

y
Double

The y-coordinate of the top-left corner of the rectangle.

width
Double

The width of the rectangle.

height
Double

The height of the rectangle.

Exceptions

width is a negative value.

-or-

height is a negative value.

Remarks

The following example shows how to create a new Rect structure by using the Rect(Double, Double, Double, Double) constructor.

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;
}

Applies to