Stores a set of four integers that represent the location and size of a rectangle
Assembly: System.Drawing (in System.Drawing.dll)
Thetype exposes the following members.
|Bottom||Gets the y-coordinate that is the sum of the Y and Height property values of this structure.|
|Height||Gets or sets the height of this structure.|
|IsEmpty||Tests whether all numeric properties of this have values of zero.|
|Left||Gets the x-coordinate of the left edge of this structure.|
|Location||Gets or sets the coordinates of the upper-left corner of this structure.|
|Right||Gets the x-coordinate that is the sum of X and Width property values of this structure.|
|Size||Gets or sets the size of this .|
|Top||Gets the y-coordinate of the top edge of this structure.|
|Width||Gets or sets the width of this structure.|
|X||Gets or sets the x-coordinate of the upper-left corner of this structure.|
|Y||Gets or sets the y-coordinate of the upper-left corner of this structure.|
|Ceiling||Converts the specified RectangleF structure to a structure by rounding the RectangleF values to the next higher integer values.|
|Contains(Point)||Determines if the specified point is contained within this structure.|
|Contains(Rectangle)||Determines if the rectangular region represented by rect is entirely contained within this structure.|
|Contains(Int32, Int32)||Determines if the specified point is contained within this structure.|
|Equals||Tests whether obj is a structure with the same location and size of this structure. (Overrides ValueType.Equals(Object).)|
|FromLTRB||Creates a structure with the specified edge locations.|
|GetHashCode||Returns the hash code for this structure. For information about the use of hash codes, see GetHashCode . (Overrides ValueType.GetHashCode().)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|Inflate(Size)||Enlarges this by the specified amount.|
|Inflate(Int32, Int32)||Enlarges this by the specified amount.|
|Inflate(Rectangle, Int32, Int32)||Creates and returns an enlarged copy of the specified structure. The copy is enlarged by the specified amount. The original structure remains unmodified.|
|Intersect(Rectangle)||Replaces this with the intersection of itself and the specified .|
|Intersect(Rectangle, Rectangle)||Returns a third structure that represents the intersection of two other structures. If there is no intersection, an empty is returned.|
|IntersectsWith||Determines if this rectangle intersects with rect.|
|Offset(Point)||Adjusts the location of this rectangle by the specified amount.|
|Offset(Int32, Int32)||Adjusts the location of this rectangle by the specified amount.|
|Round||Converts the specified RectangleF to a by rounding the RectangleF values to the nearest integer values.|
|ToString||Converts the attributes of this to a human-readable string. (Overrides ValueType.ToString().)|
In XNA Framework 3.0, this member is inherited from Object.ToString().
|Truncate||Converts the specified RectangleF to a by truncating the RectangleF values.|
|Union||Gets a structure that contains the union of two structures.|
To draw rectangles, you need a Graphics object and a Pen object. The Graphics object provides the DrawRectangle method, and the Pen object stores features of the line, such as color and width. The units the rectangle is drawn in is determined by the PageUnit and PageScale properties of the graphics object used for drawing. The default unit is pixels.
To draw a filled with color, you need a Graphics object and an object derived from Brush such as SolidBrush or LinearGradientBrush. The Graphics object provides the FillRectangle method and the Brush object provides the color and fill information.
For more advanced shapes, use a Region object.
The following example draws a rectangle with its upper-left corner at (10, 10). The rectangle has a width of 100 and a height of 50. The second argument passed to the Pen constructor indicates that the pen width is 5 pixels.
When the rectangle is drawn, the pen is centered on the rectangle's boundary. Because the pen width is 5, the sides of the rectangle are drawn 5 pixels wide, such that 1 pixel is drawn on the boundary itself, 2 pixels are drawn on the inside, and 2 pixels are drawn on the outside. For more details on pen alignment, see How to: Set Pen Width and Alignment.
The following illustration shows the resulting rectangle. The dotted lines show where the rectangle would have been drawn if the pen width had been one pixel. The enlarged view of the upper-left corner of the rectangle shows that the thick black lines are centered on those dotted lines.