Show / Hide Table of Contents

Struct Rect

Describes the width, height, and point origin of a rectangle.

Implements
System.IFormattable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: System.Windows
Assembly: OpenSilver.dll
Syntax
public struct Rect : IFormattable

Constructors

| Improve this Doc View Source

Rect(Double, Double, Double, Double)

Initializes a Rect structure that has the specified x-coordinate, y-coordinate, width, and height.

Declaration
public Rect(double x, double y, double width, double height)
Parameters
Type Name Description
System.Double x

The x-coordinate of the top-left corner of the rectangle.

System.Double y

The y-coordinate of the top-left corner of the rectangle.

System.Double width

The width of the rectangle.

System.Double height

The height of the rectangle.

Exceptions
Type Condition
System.ArgumentException

width or height are less than 0.

| Improve this Doc View Source

Rect(Point, Point)

Initializes a Rect structure that is exactly large enough to contain the two specified points.

Declaration
public Rect(Point point1, Point point2)
Parameters
Type Name Description
Point point1

The first point that the new rectangle must contain.

Point point2

The second point that the new rectangle must contain.

| Improve this Doc View Source

Rect(Point, Size)

Initializes a Rect structure based on an origin and size.

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

The origin of the new Rect.

Size size

The size of the new Rect.

| Improve this Doc View Source

Rect(Point, Vector)

Initializes a new instance of the Rect structure that is exactly large enough to contain the specified point and the sum of the specified point and the specified vector.

Declaration
public Rect(Point point, Vector vector)
Parameters
Type Name Description
Point point

The first point the rectangle must contain.

Vector vector

The amount to offset the specified point. The resulting rectangle will be exactly large enough to contain both points.

| Improve this Doc View Source

Rect(Size)

Initializes a new instance of the Rect structure that is of the specified size and is located at (0,0).

Declaration
public Rect(Size size)
Parameters
Type Name Description
Size size

The size of the new Rect.

Properties

| Improve this Doc View Source

Bottom

Gets the y-axis value of the bottom of the rectangle.

Declaration
public readonly double Bottom { get; }
Property Value
Type Description
System.Double

The y-axis value of the bottom of the rectangle. If the rectangle is empty, the value is System.Double.NegativeInfinity.

| Improve this Doc View Source

BottomLeft

Gets the position of the bottom-left corner of the rectangle. If this is the empty rectangle, the value will be positive infinity, negative infinity.

Declaration
public readonly Point BottomLeft { get; }
Property Value
Type Description
Point
| Improve this Doc View Source

BottomRight

Gets the position of the bottom-right corner of the rectangle.

Declaration
public readonly Point BottomRight { get; }
Property Value
Type Description
Point
| Improve this Doc View Source

Empty

Gets a special value that represents a rectangle with no position or area.

Declaration
public static readonly Rect Empty { get; }
Property Value
Type Description
Rect

The empty rectangle, which has X and Y property values of System.Double.PositiveInfinity, and has Width and Height property values of System.Double.NegativeInfinity.

| Improve this Doc View Source

Height

Gets or sets the height of the rectangle.

Declaration
public double Height { get; set; }
Property Value
Type Description
System.Double

A value that represents the height of the rectangle. The default is 0.

Exceptions
Type Condition
System.ArgumentException

Specified a value less than 0.

| Improve this Doc View Source

IsEmpty

Gets a value that indicates whether the rectangle is the Empty rectangle.

Declaration
public readonly bool IsEmpty { get; }
Property Value
Type Description
System.Boolean

true if the rectangle is the Empty rectangle; otherwise, false.

| Improve this Doc View Source

Left

Gets the x-axis value of the left side of the rectangle.

Declaration
public readonly double Left { get; }
Property Value
Type Description
System.Double

The x-axis value of the left side of the rectangle.

| Improve this Doc View Source

Location

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

Declaration
public Point Location { get; set; }
Property Value
Type Description
Point
| Improve this Doc View Source

Right

Gets the x-axis value of the right side of the rectangle.

Declaration
public readonly double Right { get; }
Property Value
Type Description
System.Double

The x-axis value of the right side of the rectangle.

| Improve this Doc View Source

Size

Gets or sets the width and height of the rectangle.

Declaration
public Size Size { get; set; }
Property Value
Type Description
Size
| Improve this Doc View Source

Top

Gets the y-axis position of the top of the rectangle.

Declaration
public readonly double Top { get; }
Property Value
Type Description
System.Double

The y-axis position of the top of the rectangle.

| Improve this Doc View Source

TopLeft

Gets the position of the top-left corner of the rectangle

Declaration
public readonly Point TopLeft { get; }
Property Value
Type Description
Point
| Improve this Doc View Source

TopRight

Gets the position of the top-right corner of the rectangle.

Declaration
public readonly Point TopRight { get; }
Property Value
Type Description
Point
| Improve this Doc View Source

Width

Gets or sets the width of the rectangle.

Declaration
public double Width { get; set; }
Property Value
Type Description
System.Double

A value that represents the width of the rectangle in pixels. The default is 0.

Exceptions
Type Condition
System.ArgumentException

Specified a value less than 0.

| Improve this Doc View Source

X

Gets or sets the x-axis value of the left side of the rectangle.

Declaration
public double X { get; set; }
Property Value
Type Description
System.Double

The x-axis value of the left side of the rectangle. This value is interpreted as pixels within the coordinate space.

| Improve this Doc View Source

Y

Gets or sets the y-axis value of the top side of the rectangle.

Declaration
public double Y { get; set; }
Property Value
Type Description
System.Double

The y-axis value of the top side of the rectangle. This value is interpreted as pixels within the coordinate space.

Methods

| Improve this Doc View Source

Contains(Double, Double)

Indicates whether the rectangle contains the specified x-coordinate and y-coordinate.

Declaration
public bool Contains(double x, double y)
Parameters
Type Name Description
System.Double x

The x-coordinate of the point to check.

System.Double y

The y-coordinate of the point to check.

Returns
Type Description
System.Boolean

true if (x, y) is contained by the rectangle; otherwise, false.

| Improve this Doc View Source

Contains(Point)

Indicates whether the rectangle described by the Rect contains the specified point.

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

The point to check.

Returns
Type Description
System.Boolean

true if the rectangle described by the Rect contains the specified point; otherwise, false.

| Improve this Doc View Source

Contains(Rect)

Indicates whether the rectangle contains the specified rectangle.

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

The rectangle to check.

Returns
Type Description
System.Boolean

true if rect is entirely contained by the rectangle; otherwise, false.

| Improve this Doc View Source

Equals(Object)

Indicates whether the specified object is equal to the current Rect.

Declaration
public override bool Equals(object o)
Parameters
Type Name Description
System.Object o

The object to compare to the current rectangle.

Returns
Type Description
System.Boolean

true if o is a Rect and has the same x,y,width,height values as the current Rect; otherwise, false.

Overrides
System.ValueType.Equals(System.Object)
| Improve this Doc View Source

Equals(Rect)

Indicates whether the specified Rect is equal to the current Rect.

Declaration
public bool Equals(Rect value)
Parameters
Type Name Description
Rect value

The rectangle to compare to the current rectangle.

Returns
Type Description
System.Boolean

true if the specified Rect has the same x,y,width,height property values as the current Rect; otherwise, false.

| Improve this Doc View Source

Equals(Rect, Rect)

Indicates whether the specified rectangles are equal.

Declaration
public static bool Equals(Rect rect1, Rect rect2)
Parameters
Type Name Description
Rect rect1

The first rectangle to compare.

Rect rect2

The second rectangle to compare.

Returns
Type Description
System.Boolean

true if the rectangles have the same Location and Size values; otherwise, false.

| Improve this Doc View Source

GetHashCode()

Creates a hash code for the Rect.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for the current Rect structure.

Overrides
System.ValueType.GetHashCode()
| Improve this Doc View Source

Inflate(Double, Double)

Expands or shrinks the rectangle by using the specified width and height amounts, in all directions.

Declaration
public void Inflate(double width, double height)
Parameters
Type Name Description
System.Double width

The amount by which to expand or shrink the left and right sides of the rectangle.

System.Double height

The amount by which to expand or shrink the top and bottom sides of the rectangle.

Exceptions
Type Condition
System.InvalidOperationException

This method is called on the Empty rectangle.

| Improve this Doc View Source

Inflate(Rect, Double, Double)

Creates a rectangle that results from expanding or shrinking the specified rectangle by the specified width and height amounts, in all directions.

Declaration
public static Rect Inflate(Rect rect, double width, double height)
Parameters
Type Name Description
Rect rect

The System.Windows.Rect structure to modify.

System.Double width

The amount by which to expand or shrink the left and right sides of the rectangle.

System.Double height

The amount by which to expand or shrink the top and bottom sides of the rectangle.

Returns
Type Description
Rect

The resulting rectangle.

Exceptions
Type Condition
System.InvalidOperationException

rect is an System.Windows.Rect.Empty rectangle.

| Improve this Doc View Source

Inflate(Rect, Size)

Returns the rectangle that results from expanding the specified rectangle by the specified Size, in all directions.

Declaration
public static Rect Inflate(Rect rect, Size size)
Parameters
Type Name Description
Rect rect

The Rect structure to modify.

Size size

Specifies the amount to expand the rectangle. The Size structure's Width property specifies the amount to increase the rectangle's Left and Right properties. The Size structure's Height property specifies the amount to increase the rectangle's Top and Bottom properties.

Returns
Type Description
Rect

The resulting rectangle.

Exceptions
Type Condition
System.InvalidOperationException

rect is an Empty rectangle.

| Improve this Doc View Source

Inflate(Size)

Expands the rectangle by using the specified Size, in all directions.

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

Specifies the amount to expand the rectangle. The Size structure's Width property specifies the amount to increase the rectangle's Left and Right properties. The Size structure's Height property specifies the amount to increase the rectangle's Top and Bottom properties.

Exceptions
Type Condition
System.InvalidOperationException

This method is called on the Empty rectangle.

| Improve this Doc View Source

Intersect(Rect)

Finds the intersection of the rectangle represented by the current Rect and the rectangle represented by the specified Rect, and stores the result as the current Rect.

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

The rectangle to intersect with the current rectangle.

| Improve this Doc View Source

Intersect(Rect, Rect)

Returns the intersection of the specified rectangles.

Declaration
public static Rect Intersect(Rect rect1, Rect rect2)
Parameters
Type Name Description
Rect rect1

The first rectangle to compare.

Rect rect2

The second rectangle to compare.

Returns
Type Description
Rect

The intersection of the two rectangles, or Empty if no intersection exists.

| Improve this Doc View Source

IntersectsWith(Rect)

Indicates whether the specified rectangle intersects with the current rectangle.

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

The rectangle to check.

Returns
Type Description
System.Boolean

true if the specified rectangle intersects with the current rectangle; otherwise, false.

| Improve this Doc View Source

Offset(Double, Double)

Moves the rectangle by the specified horizontal and vertical amounts.

Declaration
public void Offset(double offsetX, double offsetY)
Parameters
Type Name Description
System.Double offsetX

The amount to move the rectangle horizontally.

System.Double offsetY

The amount to move the rectangle vertically.

Exceptions
Type Condition
System.InvalidOperationException

This method is called on the Empty rectangle.

| Improve this Doc View Source

Offset(Rect, Double, Double)

Returns a rectangle that is offset from the specified rectangle by using the specified horizontal and vertical amounts.

Declaration
public static Rect Offset(Rect rect, double offsetX, double offsetY)
Parameters
Type Name Description
Rect rect

The rectangle to move.

System.Double offsetX

The horizontal offset for the new rectangle.

System.Double offsetY

The vertical offset for the new rectangle.

Returns
Type Description
Rect

The resulting rectangle.

Exceptions
Type Condition
System.InvalidOperationException

rect is Empty.

| Improve this Doc View Source

Offset(Rect, Vector)

Returns a rectangle that is offset from the specified rectangle by using the specified vector.

Declaration
public static Rect Offset(Rect rect, Vector offsetVector)
Parameters
Type Name Description
Rect rect

The original rectangle.

Vector offsetVector

A vector that specifies the horizontal and vertical offsets for the new rectangle.

Returns
Type Description
Rect

The resulting rectangle.

Exceptions
Type Condition
System.InvalidOperationException

rect is Empty.

| Improve this Doc View Source

Offset(Vector)

Moves the rectangle by the specified vector.

Declaration
public void Offset(Vector offsetVector)
Parameters
Type Name Description
Vector offsetVector

A vector that specifies the horizontal and vertical amounts to move the rectangle.

Exceptions
Type Condition
System.InvalidOperationException

This method is called on the Empty rectangle.

| Improve this Doc View Source

Parse(String)

Creates a new rectangle from the specified string representation.

Declaration
public static Rect Parse(string source)
Parameters
Type Name Description
System.String source

The string representation of the rectangle, in the form "x, y, width, height".

Returns
Type Description
Rect

The resulting rectangle.

| Improve this Doc View Source

Scale(Double, Double)

Multiplies the size of the current rectangle by the specified x and y values.

Declaration
public void Scale(double scaleX, double scaleY)
Parameters
Type Name Description
System.Double scaleX

The scale factor in the x-direction.

System.Double scaleY

The scale factor in the y-direction.

| Improve this Doc View Source

ToString()

Returns a string representation of the Rect structure. structure.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string representation of the current Rect structure. The string has the following form: "X, Y, Width, Height".

Overrides
System.ValueType.ToString()
| Improve this Doc View Source

ToString(IFormatProvider)

Returns a string representation of the rectangle by using the specified format provider.

Declaration
public string ToString(IFormatProvider provider)
Parameters
Type Name Description
System.IFormatProvider provider

Culture-specific formatting information.

Returns
Type Description
System.String

A string representation of the current rectangle that is determined by the specified format provider.

| Improve this Doc View Source

Transform(Matrix)

Transforms the rectangle by applying the specified matrix.

Declaration
public void Transform(Matrix matrix)
Parameters
Type Name Description
Matrix matrix

A matrix that specifies the transformation to apply.

| Improve this Doc View Source

Transform(Rect, Matrix)

Returns the rectangle that results from applying the specified matrix to the specified rectangle.

Declaration
public static Rect Transform(Rect rect, Matrix matrix)
Parameters
Type Name Description
Rect rect

A rectangle that is the basis for the transformation.

Matrix matrix

A matrix that specifies the transformation to apply.

Returns
Type Description
Rect

The rectangle that results from the operation.

| Improve this Doc View Source

Union(Point)

Expands the rectangle represented by the current Rect exactly enough to contain the specified point.

Declaration
public void Union(Point point)
Parameters
Type Name Description
Point point

The point to include.

| Improve this Doc View Source

Union(Rect)

Expands the rectangle represented by the current Rect exactly enough to contain the specified rectangle.

Declaration
public void Union(Rect rect)
Parameters
Type Name Description
Rect rect

The rectangle to include.

| Improve this Doc View Source

Union(Rect, Point)

Creates a rectangle that is exactly large enough to include the specified rectangle and the specified point.

Declaration
public static Rect Union(Rect rect, Point point)
Parameters
Type Name Description
Rect rect

The rectangle to include.

Point point

The point to include.

Returns
Type Description
Rect

A rectangle that is exactly large enough to contain the specified rectangle and the specified point.

| Improve this Doc View Source

Union(Rect, Rect)

Creates a rectangle that is exactly large enough to contain the two specified rectangles.

Declaration
public static Rect Union(Rect rect1, Rect rect2)
Parameters
Type Name Description
Rect rect1

The first rectangle to include.

Rect rect2

The second rectangle to include.

Returns
Type Description
Rect

The resulting rectangle.

Operators

| Improve this Doc View Source

Equality(Rect, Rect)

Compares two Rect structures for equality.

Declaration
public static bool operator ==(Rect rect1, Rect rect2)
Parameters
Type Name Description
Rect rect1

The first rectangle to compare.

Rect rect2

The second rectangle to compare.

Returns
Type Description
System.Boolean

true if the Rect structures have the same x,y,width,height property values; otherwise, false.

| Improve this Doc View Source

Inequality(Rect, Rect)

Compares two Rect structures for inequality.

Declaration
public static bool operator !=(Rect rect1, Rect rect2)
Parameters
Type Name Description
Rect rect1

The first rectangle to compare.

Rect rect2

The second rectangle to compare.

Returns
Type Description
System.Boolean

true if the Rect structures do not have the same x,y,width,height property values; otherwise, false.

Explicit Interface Implementations

| Improve this Doc View Source

IFormattable.ToString(String, IFormatProvider)

Creates a string representation of this object based on the format string and IFormatProvider passed in. If the provider is null, the CurrentCulture is used. See the documentation for IFormattable for more information.

Declaration
string IFormattable.ToString(string format, IFormatProvider provider)
Parameters
Type Name Description
System.String format
System.IFormatProvider provider
Returns
Type Description
System.String

A string representation of this object.

Implements

System.IFormattable
  • Improve this Doc
  • View Source