• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Struct Rectangle

Represents the location and size of a rectangular region, using integer coordinates.

Implements
IEquatable<Rectangle>
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: DRIT.Drawing.Geometry
Assembly: DRIT.Drawing.dll
Syntax
public struct Rectangle : IEquatable<Rectangle>
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Constructors

Rectangle(Point, Size)

Initializes a new Rectangle from a point and a size.

Declaration
public Rectangle(Point location, Size size)
Parameters
Type Name Description
Point location

The top-left corner.

Size size

The dimensions.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Rectangle(int, int, int, int)

Initializes a new Rectangle with the specified location and size.

Declaration
public Rectangle(int x, int y, int width, int height)
Parameters
Type Name Description
int x

The x-coordinate of the top-left corner.

int y

The y-coordinate of the top-left corner.

int width

The width.

int height

The height.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Fields

Empty

Gets an empty Rectangle (0, 0, 0, 0).

Declaration
public static readonly Rectangle Empty
Field Value
Type Description
Rectangle
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Height

Gets or sets the height.

Declaration
public int Height
Field Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Width

Gets or sets the width.

Declaration
public int Width
Field Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

X

Gets or sets the x-coordinate of the top-left corner.

Declaration
public int X
Field Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Y

Gets or sets the y-coordinate of the top-left corner.

Declaration
public int Y
Field Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Properties

Bottom

Gets the y-coordinate of the bottom edge.

Declaration
public int Bottom { get; }
Property Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

IsEmpty

Gets a value indicating whether this rectangle is empty (Width or Height less than or equal to 0).

Declaration
public bool IsEmpty { get; }
Property Value
Type Description
bool
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Left

Gets the x-coordinate of the left edge.

Declaration
public int Left { get; }
Property Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Location

Gets or sets the top-left corner of this rectangle.

Declaration
public Point Location { get; set; }
Property Value
Type Description
Point
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Right

Gets the x-coordinate of the right edge.

Declaration
public int Right { get; }
Property Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Size

Gets or sets the dimensions of this rectangle.

Declaration
public Size Size { get; set; }
Property Value
Type Description
Size
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Top

Gets the y-coordinate of the top edge.

Declaration
public int Top { get; }
Property Value
Type Description
int
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Methods

Contains(Point)

Determines whether the specified point is contained within this rectangle.

Declaration
public bool Contains(Point pt)
Parameters
Type Name Description
Point pt

The point to check.

Returns
Type Description
bool

true if the point is within the rectangle; otherwise, false.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Contains(Rectangle)

Determines whether the specified rectangle is fully contained within this rectangle.

Declaration
public bool Contains(Rectangle rect)
Parameters
Type Name Description
Rectangle rect

The rectangle to check.

Returns
Type Description
bool

true if the rectangle is fully contained; otherwise, false.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Contains(int, int)

Determines whether the specified point is contained within this rectangle.

Declaration
public bool Contains(int x, int y)
Parameters
Type Name Description
int x

The x-coordinate of the point.

int y

The y-coordinate of the point.

Returns
Type Description
bool

true if the point is within the rectangle; otherwise, false.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Equals(Rectangle)

Indicates whether this rectangle is equal to another rectangle.

Declaration
public bool Equals(Rectangle other)
Parameters
Type Name Description
Rectangle other

The rectangle to compare.

Returns
Type Description
bool

true if the rectangles are equal; otherwise, false.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Equals(object?)

Indicates whether this rectangle is equal to another object.

Declaration
public override bool Equals(object? obj)
Parameters
Type Name Description
object obj

The object to compare.

Returns
Type Description
bool

true if the objects are equal; otherwise, false.

Overrides
ValueType.Equals(object)
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

FromLTRB(int, int, int, int)

Creates a rectangle from left, top, right, and bottom coordinates.

Declaration
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
Parameters
Type Name Description
int left

The x-coordinate of the left edge.

int top

The y-coordinate of the top edge.

int right

The x-coordinate of the right edge.

int bottom

The y-coordinate of the bottom edge.

Returns
Type Description
Rectangle

A new Rectangle.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

GetHashCode()

Returns a hash code for this rectangle.

Declaration
public override int GetHashCode()
Returns
Type Description
int

The hash code.

Overrides
ValueType.GetHashCode()
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Inflate(Rectangle, int, int)

Returns an inflated copy of the specified rectangle.

Declaration
public static Rectangle Inflate(Rectangle rect, int x, int y)
Parameters
Type Name Description
Rectangle rect

The rectangle to inflate.

int x

The horizontal inflation amount.

int y

The vertical inflation amount.

Returns
Type Description
Rectangle

The inflated rectangle.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Inflate(Size)

Inflates this rectangle by the specified size.

Declaration
public void Inflate(Size size)
Parameters
Type Name Description
Size size

The size to inflate by.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Inflate(int, int)

Inflates this rectangle by the specified width and height.

Declaration
public void Inflate(int width, int height)
Parameters
Type Name Description
int width

The horizontal inflation amount.

int height

The vertical inflation amount.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Intersect(Rectangle)

Intersects this rectangle with another, modifying this rectangle to the result.

Declaration
public void Intersect(Rectangle rect)
Parameters
Type Name Description
Rectangle rect

The rectangle to intersect with.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Intersect(Rectangle, Rectangle)

Returns the intersection of two rectangles.

Declaration
public static Rectangle Intersect(Rectangle a, Rectangle b)
Parameters
Type Name Description
Rectangle a

The first rectangle.

Rectangle b

The second rectangle.

Returns
Type Description
Rectangle

The intersection rectangle, or Empty if they don't intersect.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

IntersectsWith(Rectangle)

Determines whether this rectangle intersects with another rectangle.

Declaration
public bool IntersectsWith(Rectangle rect)
Parameters
Type Name Description
Rectangle rect

The rectangle to check.

Returns
Type Description
bool

true if the rectangles intersect; otherwise, false.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Offset(Point)

Offsets this rectangle by the specified point.

Declaration
public void Offset(Point pos)
Parameters
Type Name Description
Point pos

The point containing the offsets.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Offset(int, int)

Offsets this rectangle by the specified horizontal and vertical amounts.

Declaration
public void Offset(int dx, int dy)
Parameters
Type Name Description
int dx

The horizontal offset.

int dy

The vertical offset.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

ToRectangleF()

Converts this Rectangle to a RectangleF.

Declaration
public RectangleF ToRectangleF()
Returns
Type Description
RectangleF

A new RectangleF with the same dimensions.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

ToString()

Returns a string representation of this rectangle.

Declaration
public override string ToString()
Returns
Type Description
string

A string in the format "{X=value, Y=value, Width=value, Height=value}".

Overrides
ValueType.ToString()
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Union(Rectangle, Rectangle)

Returns the union of two rectangles.

Declaration
public static Rectangle Union(Rectangle a, Rectangle b)
Parameters
Type Name Description
Rectangle a

The first rectangle.

Rectangle b

The second rectangle.

Returns
Type Description
Rectangle

The smallest rectangle containing both input rectangles.

Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Operators

operator ==(Rectangle, Rectangle)

Compares two rectangles for equality.

Declaration
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
Type Name Description
Rectangle left
Rectangle right
Returns
Type Description
bool
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

operator !=(Rectangle, Rectangle)

Compares two rectangles for inequality.

Declaration
public static bool operator !=(Rectangle left, Rectangle right)
Parameters
Type Name Description
Rectangle left
Rectangle right
Returns
Type Description
bool
Remarks

A Rectangle defines a region with X, Y, Width, and Height. X and Y represent the top-left corner; Width and Height represent the dimensions.

Implements

IEquatable<T>
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX