Skip to content
CShift0.45

Rect

Struct · namespace System.Drawing · Since 0.45

struct Rect : IEquatable<Rect>, IHashable

A rectangle in pixels: X and Y are its top left corner. The right and bottom edges are outside: the rectangle covers the columns X to X + Width - 1.

Name Description
X The left edge.
Y The top edge.
Width The width in pixels.
Height The height in pixels.
int X

The left edge.

int Y

The top edge.

int Width

The width in pixels.

int Height

The height in pixels.

Name Description
Create A rectangle with its top left corner at (x, y).
FromEdges The rectangle from (left, top) to (right, bottom), which are outside.
static Rect Create(int x, int y, int width, int height)

A rectangle with its top left corner at (x, y).

static Rect Create(Point position, Size size)

A rectangle with its top left corner at position.

static Rect FromEdges(int left, int top, int right, int bottom)

The rectangle from (left, top) to (right, bottom), which are outside.

Name Description
Right The first column to the right of the rectangle.
Bottom The first row below the rectangle.
Position The top left corner.
Size The width and the height.
Center The center (rounded down).
Contains True if the point lies inside (the right and bottom edges are outside).
Intersects True if both rectangles share at least one pixel (a collision of two sprites).
Intersect The part that both rectangles cover (empty if they do not overlap).
Union The smallest rectangle that covers both (an empty one does not count).
Offset The rectangle moved by (dx, dy).
Shrink The rectangle made smaller by amount on every side (larger for a negative amount).
IsEmpty True if it covers no pixel.
Equals True if both have the same position and size.
GetHashCode A hash code of the position and the size.
ToString “(x, y, width x height)”.
int Right()

The first column to the right of the rectangle.

int Bottom()

The first row below the rectangle.

Point Position()

The top left corner.

Size Size()

The width and the height.

Point Center()

The center (rounded down).

bool Contains(int x, int y)

True if the point lies inside (the right and bottom edges are outside).

bool Contains(Point point)

True if the point lies inside (the right and bottom edges are outside).

bool Contains(Rect other)

True if other lies completely inside.

bool Intersects(Rect other)

True if both rectangles share at least one pixel (a collision of two sprites).

Rect Intersect(Rect other)

The part that both rectangles cover (empty if they do not overlap).

Rect Union(Rect other)

The smallest rectangle that covers both (an empty one does not count).

Rect Offset(int dx, int dy)

The rectangle moved by (dx, dy).

Rect Offset(Point delta)

The rectangle moved by delta.

Rect Shrink(int amount)

The rectangle made smaller by amount on every side (larger for a negative amount).

bool IsEmpty()

True if it covers no pixel.

bool Equals(Rect other)

True if both have the same position and size.

int GetHashCode()

A hash code of the position and the size.

string ToString()

“(x, y, width x height)”.