Struct Rectangle
Stores the location and size of a rectangular region.
public struct Rectangle
- Inherited Members
Constructors
Rectangle(Point, Size)
Initializes a new instance of the Rectangle class with the specified location and size.
public Rectangle(Point location, Size size)
Parameters
Rectangle(int, int, int, int)
Initializes a new instance of the Rectangle class with the specified location and size.
public Rectangle(int x, int y, int width, int height)
Parameters
Fields
Empty
Creates a new instance of the Rectangle class with member data left uninitialized.
public static readonly Rectangle Empty
Field Value
Properties
Bottom
Gets the y-coordinate of the lower-right corner of the rectangular region defined by this Rectangle.
public readonly int Bottom { get; }
Property Value
Height
Gets or sets the width of the rectangular region defined by this Rectangle.
public int Height { readonly get; set; }
Property Value
IsEmpty
public readonly bool IsEmpty { get; }
Property Value
Left
Gets the x-coordinate of the upper-left corner of the rectangular region defined by this Rectangle .
public readonly int Left { get; }
Property Value
Location
Gets or sets the coordinates of the upper-left corner of the rectangular region represented by this Rectangle.
public Point Location { readonly get; set; }
Property Value
Right
Gets the x-coordinate of the lower-right corner of the rectangular region defined by this Rectangle.
public readonly int Right { get; }
Property Value
Size
Gets or sets the size of this Rectangle.
public Size Size { readonly get; set; }
Property Value
Top
Gets the y-coordinate of the upper-left corner of the rectangular region defined by this Rectangle.
public readonly int Top { get; }
Property Value
Width
Gets or sets the width of the rectangular region defined by this Rectangle.
public int Width { readonly get; set; }
Property Value
X
Gets or sets the x-coordinate of the upper-left corner of the rectangular region defined by this Rectangle.
public int X { readonly get; set; }
Property Value
Y
Gets or sets the y-coordinate of the upper-left corner of the rectangular region defined by this Rectangle.
public int Y { readonly get; set; }
Property Value
Methods
Contains(Point)
Determines if the specified point is contained within the rectangular region defined by this Rectangle .
public readonly bool Contains(Point pt)
Parameters
pt
Point
Returns
Contains(Rectangle)
Determines if the rectangular region represented by rect
is entirely contained within the
rectangular region represented by this Rectangle .
public readonly bool Contains(Rectangle rect)
Parameters
rect
Rectangle
Returns
Contains(int, int)
Determines if the specified point is contained within the rectangular region defined by this Rectangle .
public readonly bool Contains(int x, int y)
Parameters
Returns
Equals(Rectangle)
Tests whether other
has the same location and size of this Rectangle.
public readonly bool Equals(Rectangle other)
Parameters
other
Rectangle
Returns
Equals(object?)
Tests whether other
is a Rectangle with the same location
and size of this Rectangle.
public override readonly bool Equals(object? other)
Parameters
other
object
Returns
FromLTRB(int, int, int, int)
Creates a new Rectangle with the specified location and size.
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
Parameters
Returns
GetHashCode()
Serves as the default hash function.
public override readonly int GetHashCode()
Returns
- int
A hash code for the current object.
Inflate(Rectangle, int, int)
Creates a Rectangle that is inflated by the specified amount.
public static Rectangle Inflate(Rectangle rect, int x, int y)
Parameters
Returns
Inflate(Size)
Inflates this Rectangle by the specified amount.
public void Inflate(Size size)
Parameters
size
Size
Inflate(int, int)
Inflates this Rectangle by the specified amount.
public void Inflate(int width, int height)
Parameters
Intersect(Rectangle)
Creates a Rectangle that represents the intersection between this Rectangle and rect.
public void Intersect(Rectangle rect)
Parameters
rect
Rectangle
Intersect(Rectangle, Rectangle)
Creates a rectangle that represents the intersection between a and b. 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 readonly bool IntersectsWith(Rectangle rect)
Parameters
rect
Rectangle
Returns
Offset(Point)
Adjusts the location of this rectangle by the specified amount.
public void Offset(Point pos)
Parameters
pos
Point
Offset(int, int)
Adjusts the location of this rectangle by the specified amount.
public void Offset(int x, int y)
Parameters
ToString()
Converts the attributes of this Rectangle to a human readable string.
public override readonly string ToString()
Returns
Union(Rectangle, Rectangle)
Creates a rectangle that represents the union between a and b.
public static Rectangle Union(Rectangle a, Rectangle b)
Parameters
Returns
Operators
operator ==(Rectangle, Rectangle)
Tests whether two Rectangle objects have equal location and size.
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
Returns
operator !=(Rectangle, Rectangle)
Tests whether two Rectangle objects differ in location or size.
public static bool operator !=(Rectangle left, Rectangle right)