Struct Rectangle
Stores a set of four integers that represent the location and size of a rectangle.
public struct Rectangle
- Inherited Members
Constructors
Rectangle(Point, Size)
Initializes a new instance of the Rectangle structure with the specified location and size.
public Rectangle(Point location, Size size)
Parameters
location
PointA Point that represents the upper-left corner of the rectangular region.
size
SizeA Size that represents the width and height of the rectangular region.
Rectangle(int, int, int, int)
Initializes a new instance of the Rectangle structure with the specified location and size.
public Rectangle(int x, int y, int width, int height)
Parameters
x
intThe x-coordinate of the upper-left corner of the rectangle.
y
intThe y-coordinate of the upper-left corner of the rectangle.
width
intThe width of the rectangle.
height
intThe height of the rectangle.
Properties
Bottom
Gets or sets the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure.
public int Bottom { get; set; }
Property Value
Empty
public static Rectangle Empty { get; }
Property Value
Height
Gets or sets the height of this Rectangle structure.
public int Height { get; set; }
Property Value
IsEmpty
Gets a value indicating whether all numeric properties of this Rectangle have values of zero.
public bool IsEmpty { get; }
Property Value
- bool
This property returns true if the Width, Height, X, and Y properties of this Rectangle all have values of zero; otherwise, false.
Left
Gets or sets the x-coordinate of the left edge of this Rectangle structure.
public int Left { get; set; }
Property Value
Location
Gets or sets the coordinates of the upper-left corner of this Rectangle structure.
public Point Location { get; set; }
Property Value
Right
Gets or sets the x-coordinate that is the sum of X and Width property values of this Rectangle structure.
public int Right { get; set; }
Property Value
Size
Gets or sets the size of this Rectangle.
public Size Size { get; set; }
Property Value
Top
Gets or sets the y-coordinate of the top edge of this Rectangle structure.
public int Top { get; set; }
Property Value
Width
Gets or sets the width of this Rectangle structure.
public int Width { get; set; }
Property Value
X
Gets or sets the x-coordinate of the upper-left corner of this Rectangle structure.
public int X { get; set; }
Property Value
Y
Gets or sets the y-coordinate of the upper-left corner of this Rectangle structure.
public int Y { get; set; }
Property Value
Methods
Ceiling(RectangleF)
Converts the specified RectangleF structure to a Rectangle structure by rounding the RectangleF values to the next higher integer values.
public static Rectangle Ceiling(RectangleF value)
Parameters
value
RectangleFThe RectangleF structure to be converted.
Returns
Contains(Point)
Determines if the specified point is contained within this Rectangle structure.
public bool Contains(Point point)
Parameters
Returns
- bool
This method returns true if the point represented by
point
is contained within this Rectangle structure; otherwise false.
Contains(Rectangle)
Determines if the rectangular region represented by rect
is entirely contained within this Rectangle structure.
public bool Contains(Rectangle rect)
Parameters
Returns
- bool
This method returns true if the rectangular region represented by
rect
is entirely contained within this Rectangle structure; otherwise false.
Contains(int, int)
Determines if the specified point is contained within this Rectangle structure.
public bool Contains(int x, int y)
Parameters
Returns
- bool
This method returns true if the point defined by
x
andy
is contained within this Rectangle structure; otherwise false.
Equals(object)
Tests whether obj
is a Rectangle structure with the same location and size of this Rectangle structure.
public override bool Equals(object obj)
Parameters
Returns
- bool
This method returns true if
obj
is a Rectangle structure and its X, Y, Width, and Height properties are equal to the corresponding properties of this Rectangle structure; otherwise, false.
FromLeftTopRightBottom(int, int, int, int)
Creates a Rectangle structure with the specified edge locations.
public static Rectangle FromLeftTopRightBottom(int left, int top, int right, int bottom)
Parameters
left
intThe x-coordinate of the upper-left corner of this Rectangle structure.
top
intThe y-coordinate of the upper-left corner of this Rectangle structure.
right
intThe x-coordinate of the lower-right corner of this Rectangle structure.
bottom
intThe y-coordinate of the lower-right corner of this Rectangle structure.
Returns
FromPoints(Point, Point)
Creates a new Rectangle from two points specified. Two verticales of the created Rectangle will be equal to the passed point1
and point2
. These would be typically the opposite vertices.
public static Rectangle FromPoints(Point point1, Point point2)
Parameters
point1
PointThe first Point for the new rectangle.
point2
PointThe second Point for the new rectangle.
Returns
GetHashCode()
Returns the hash code for this Rectangle structure.
public override int GetHashCode()
Returns
- int
An integer that represents the hash code for this rectangle.
Inflate(Rectangle, int, int)
Creates and returns an inflated copy of the specified Rectangle structure. The copy is inflated by the specified amount. The original Rectangle structure remains unmodified.
public static Rectangle Inflate(Rectangle rect, int x, int y)
Parameters
rect
RectangleThe Rectangle with which to start. This rectangle is not modified.
x
intThe amount to inflate this Rectangle horizontally.
y
intThe amount to inflate this Rectangle vertically.
Returns
Inflate(Size)
Inflates this Rectangle by the specified amount.
public void Inflate(Size size)
Parameters
size
SizeThe amount to inflate this rectangle.
Inflate(int, int)
Inflates this Rectangle by the specified amount.
public void Inflate(int width, int height)
Parameters
width
intThe amount to inflate this Rectangle horizontally.
height
intThe amount to inflate this Rectangle vertically.
Intersect(Rectangle)
public void Intersect(Rectangle rect)
Parameters
Intersect(Rectangle, Rectangle)
Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. If there is no intersection, an empty Rectangle is returned.
public static Rectangle Intersect(Rectangle a, Rectangle b)
Parameters
Returns
IntersectsWith(Rectangle)
Determines if this rectangle intersects with rect
.
public bool IntersectsWith(Rectangle rect)
Parameters
rect
RectangleThe rectangle to test.
Returns
- bool
This method returns true if there is any intersection, otherwise false.
Normalize()
Normalizes the rectangle by making it's width and height positive, left less than right and top less than bottom.
public void Normalize()
Offset(Point)
Adjusts the location of this rectangle by the specified amount.
public void Offset(Point pos)
Parameters
pos
PointAmount to offset the location.
Offset(int, int)
Adjusts the location of this rectangle by the specified amount.
public void Offset(int x, int y)
Parameters
Round(RectangleF)
Converts the specified RectangleF to a Rectangle by rounding the RectangleF values to the nearest integer values.
public static Rectangle Round(RectangleF value)
Parameters
value
RectangleFThe RectangleF to be converted.
Returns
ToString()
Converts the attributes of this Rectangle to a human-readable string.
public override string ToString()
Returns
Truncate(RectangleF)
Converts the specified RectangleF to a Rectangle by truncating the RectangleF values.
public static Rectangle Truncate(RectangleF value)
Parameters
value
RectangleFThe RectangleF to be converted.
Returns
Union(Rectangle, Rectangle)
public static Rectangle Union(Rectangle a, Rectangle b)
Parameters
Returns
Operators
operator ==(Rectangle, Rectangle)
Tests whether two Rectangle structures have equal location and size.
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
left
RectangleThe Rectangle structure that is to the left of the equality operator.
right
RectangleThe Rectangle structure that is to the right of the equality operator.
Returns
- bool
This operator returns true if the two Rectangle structures have equal X, Y, Width, and Height properties.
operator !=(Rectangle, Rectangle)
Tests whether two Rectangle structures differ in location or size.
public static bool operator !=(Rectangle left, Rectangle right)
Parameters
left
RectangleThe Rectangle structure that is to the left of the inequality operator.
right
RectangleThe Rectangle structure that is to the right of the inequality operator.