Like every geometric representation in your program, a rectangular figure is based on a coordinate system whose origin is located on a top-left corner. The object that "owns" or defines the rectangle also owns this origin.
To completely represent it, a rectangle is defined by its location and it size. The location is defined by a point on the top-left corner of the rectangle:
Based on this, a rectangle can be illustrated as follows:
To create a rectangle, you must provide at least its location and dimensions. The location can be represented by a Point value and the dimensions can be represented with a Size value. Based on this, you can use the following constructor to declare a Rectangle variable: public Rectangle(Point location, Size size); The equivalent RectangleF constructor uses the following syntax: public RectangleF(PointF location, SizeF size); This constructor requires that you define a Point (or PointF) and a Size (or SizeF) in order to use it. If instead you know the integer values of the location and dimensions, you can use the following constructor to declare a Rectangle object: public Rectangle(int x, int y, int width, int height); The equivalent RectangleF constructor has the following syntax: public RectangleF(float x, float y, float width, float height); At any time, you can access or retrieve the characteristics of a Rectangle object as illustrated in the above picture from its properties. You use the same names we used in the picture.
|
|||||||||||||||||||||