RectangleF
ReferencesRepresents a floating point rectangle with a location (X, Y) and size (Width, Height) components.
Remarks: A rectangle is defined by a location (X, Y) and a size (Width, Height). The width and/or height can be negative.
Constructors
RectangleF
#Initializes a new instance of the Rectangle class with the specified
x, y, width, and heightFields
Empty
#Gets an empty rectangle with zero X, Y, Width, and Height components
Remarks: Useful when you want a rectangle no size or location.
Properties
Bottom
#Gets or sets the logical bottom of this rectangle (Y + Height if Height is positive, Y + 1 if negative)
Remarks: This differs from the InnerBottom in that this will return the co-ordinate adjacent to the bottom edge of the rectangle, whereas InnerBottom returns the co-ordinate that is inside the rectangle
BottomLeft
#BottomRight
#EndLocation
#Gets the ending location of this rectangle
InnerBottom
#Gets or sets the bottom of the rectangle that is inside the bounds
Remarks: Similar to Bottom but inside the rectangle's bounds instead of just below the bottom
InnerBottomLeft
#Gets or sets the point at the InnerBottom and Left of the rectangle
Remarks: Similar to BottomLeft but inside the rectangle's bounds instead of just below the bottom
InnerBottomRight
#Gets or sets the point at the InnerBottom and InnerRight of the rectangle
Remarks: Similar to BottomRight but inside the rectangle's bounds instead of just to the right and bottom
InnerRight
#Gets or sets the right of the rectangle that is inside the bounds
Remarks: Similar to Right but inside the rectangle's bounds instead of just to the right
InnerTopRight
#Gets or sets the point at the Top and InnerRight of the rectangle
Remarks: Similar to TopRight but inside the rectangle's bounds instead of just to the right
IsEmpty
#Gets a value indicating that the Size of this rectangle is empty (either the width or height are zero)
IsZero
#Gets a value indicating that both the and Size of this rectangle are zero
Remarks: The X, Y, Width, and Height components of this rectangle must be zero for this to return true.
Left
#Gets or sets the logical left of this rectangle (X co-ordinate if Width is positive, X + Width if negative)
MiddleBottom
#MiddleLeft
#MiddleRight
#MiddleTop
#Right
#Gets or sets the logical right of this rectangle (X + Width if Width is positive, X + 1 if negative)
Remarks: This differs from the InnerRight in that this will return the co-ordinate adjacent to the right edge of the rectangle, whereas InnerRight returns the co-ordinate that is inside the rectangle
Top
#Gets or sets the logical top of this rectangle (Y co-ordinate if Height is positive, Y + Height if negative)
Remarks: This is always the logical top, where if the Height is positive it will adjust the Y co-ordinate. If the Height of the rectangle is negative, then this will adjust the Height when setting the value.
TopLeft
#TopRight
#Methods
Align
#Aligns the
rectangle to a grid of the specified gridWidth and gridHeightRemarks: This will align the top, left, right, and bottom to a grid by inflating each edge to the next grid line.
Parameters:
| rectangle (RectangleF) | Rectangle to align |
| gridWidth (float) | Grid width |
| gridHeight (float) | Grid height |
Returns: A new Rectangle aligned to the grid
Align
#Aligns the
rectangle to a grid of the specified gridSizeRemarks: This will align the top, left, right, and bottom to a grid by inflating each edge to the next grid line.
Parameters:
| rectangle (RectangleF) | Rectangle to align |
| gridSize (SizeF) | Size of the grid to align the rectangle to |
Returns: A new Rectangle aligned to the grid
Align
#Aligns the rectangle to a grid of the specified
gridWidth and gridHeightRemarks: This will align the top, left, right, and bottom to a grid by inflating each edge to the next grid line.
Align
#Aligns the rectangle to a grid of the specified
gridSizeRemarks: This will align the top, left, right, and bottom to a grid by inflating each edge to the next grid line.
Parameters:
| gridSize (SizeF) | Size of the grid to align the rectangle to |
Contains
#Gets a value indicating that the specified
x and y co-ordinates are within the bounds of this rectangleReturns: True if the rectangle contains the x and y co-ordinates, false otherwise
Contains
#Gets a value indicating that the specified
point is within the bounds of this rectangleParameters:
| point (PointF) | Point to test |
Returns: True if the point is within the bounds of this rectangle, false if it is outside the bounds
Contains
#Gets a value indicating that the specified
rectangle is entirely contained within the bounds of this rectangleParameters:
| rectangle (RectangleF) | Rectangle to test if it is contained within this instance |
Distance
#Calculates the distance between the specified
point and rect.Remarks: This calculates the horizontal and vertical distance of any of the edges of the rectangle to the specified point.
Parameters:
| rect (RectangleF) | Rectangle for the source. |
| point (PointF) | Point to determine the distance from the rectangle. |
Distance
#Calculates the distance between two rectangles.
Remarks: This calculates the horizontal and vertical distance of any of the edges of each rectangle. If the rectangles intersect, the distance will be empty.
Parameters:
| rect1 (RectangleF) | First rectangle to compare |
| rect2 (RectangleF) | Second rectangle to compare |
Equals
#Compares this rectangle to an object for equality
Parameters:
| obj (object) | Object to compare with |
Returns: True if the
obj is a Rectangle and is equal to this instance, false otherwiseOverrides: ValueType.Equals
Equals
#Compares this rectangle with the specified
other rectangleParameters:
| other (RectangleF) | Other rectangle to compare with |
Returns: True if the
other rectangle is equal to this instance, false otherwiseFromCenter
#Creates a new instance of a RectangleF with a specified
center and sizeReturns: A new instance of a RectangleF with the specified center and size
FromSides
#Creates a new instance of a RectangleF from the values of the
left, top, right and bottom sidesGetHashCode
#Gets the hash code for this rectangle
Returns: Hash code value for this rectangle
Overrides: ValueType.GetHashCode
Inflate
#Inflates all dimensions of this
rectangle by the specified width and heightRemarks: This inflates the
rectangle in all dimensions by the specified width and height. The resulting rectangle will be increased in width and height twice that of the specified size, and the center will be in the same location. A negative width and/or height can be passed in to deflate the rectangle.Parameters:
| rectangle (RectangleF) | Rectangle to inflate |
| width (float) | Width to inflate the left and right of the rectangle by |
| height (float) | Height to inflate the top and bottom of the rectangle by |
Returns: A new rectangle inflated by the specified width and height
Inflate
#Inflates all dimensions of the
rectangle by the specified sizeRemarks: This inflates the
rectangle in all dimensions by the width and height specified by size. The resulting rectangle will be increased in width and height twice that of the specified size, and the center will be in the same location. A negative width and/or height can be passed in to deflate the rectangle.Parameters:
| rectangle (RectangleF) | Rectangle to inflate |
| size (SizeF) | Size to inflate the rectangle by |
Returns: A new rectangle inflated by the specified width and height
Inflate
#Inflates all dimensions of this rectangle by the specified
width and heightRemarks: This inflates the rectangle in all dimensions by the specified
width and height. The resulting rectangle will be increased in width and height twice that of the specified size, and the center will be in the same location. A negative width and/or height can be passed in to deflate the rectangle.Inflate
#Inflates all dimensions of this rectangle by the specified
sizeRemarks: This inflates the rectangle in all dimensions by the width and height specified by
size. The resulting rectangle will be increased in width and height twice that of the specified size, and the center will be in the same location. A negative width and/or height can be passed in to deflate the rectangle.Parameters:
| size (SizeF) | Size to inflate the rectangle by |
Inset
#Returns a new rectangle that is inset by the specified
paddingParameters:
| rectangle (RectangleF) | Rectangle to inset |
| padding (PaddingF) | Padding to inset by |
Returns: A new rectangle inset by the specified padding
Inset
#Insets the rectangle by the specified padding.
Parameters:
| padding (PaddingF) | Padding to inset this rectangle by |
Intersect
#Intersect the two specified rectangles
Parameters:
| rect1 (RectangleF) | First rectangle to intersect |
| rect2 (RectangleF) | Second rectangle to intersect |
Returns: A new RectangleF with the intersection of the two rectangles
Intersect
#Intersect the rectangle with the specified
rectangleParameters:
| rectangle (RectangleF) | Rectangle to intersect with |
Intersects
#Gets a value indicating that the specified
rectangle overlaps this rectangleParameters:
| rectangle (RectangleF) | Rectangle to test for intersection/overlap |
Returns: True if the rectangle overlaps this instance, false otherwise
Normalize
#public void Normalize()
Normalizes the rectangle so both the Width and Height are positive, without changing the location of the rectangle
Offset
#Offsets the location of the
rectangle by the specified x and y valuesParameters:
| rectangle (RectangleF) | Rectangle to offset |
| x (float) | Horizontal offset to move the rectangle |
| y (float) | Vertical offset to move the rectangle |
Returns: A new Rectangle with the offset location
Offset
#Offsets the location of the
rectangle by the X and Y values of the specified pointParameters:
| rectangle (RectangleF) | Rectangle to offset |
| point (PointF) | Point with values to offset the rectangle |
Returns: A new Rectangle with the offset location
Offset
#Offsets the location of the
rectangle by the specified sizeParameters:
| rectangle (RectangleF) | Rectangle to inflate |
| size (SizeF) | Width and Height to move the rectangle |
Returns: A new Rectangle with the offset location
Offset
#Offsets the location of the rectangle by the specified
x and y valuesOffset
#Offsets the location of the rectangle by the X and Y values of the specified
pointParameters:
| point (PointF) | Point with values to offset the rectangle |
Offset
#Offsets the location of the rectangle by the specified
sizeParameters:
| size (SizeF) | Width and Height to move the rectangle |
Restrict
#Restricts the
rectangle to be within the restrict rectangleRemarks: This ensures that
rectangle's bounds fall within the bounds of the specified restrict rectangle It is useful to ensure that the rectangle does not exceed certain limits (e.g. for drawing)Returns: A new rectangle restricted to the restrict bounds
Restrict
#Restricts the rectangle to be within the specified
point and sizeRemarks: This is a shortcut for Restrict(RectangleF)
Restrict
#Restricts the rectangle to be within the specified
rectangleRemarks: This ensures that the current rectangle's bounds fall within the bounds of the specified
rectangle. It is useful to ensure that the rectangle does not exceed certain limits (e.g. for drawing)Parameters:
| rectangle (RectangleF) | Rectangle to restrict this instance to |
Restrict
#Restricts the rectangle to be within the specified
size at an X,Y location of 0, 0Remarks: This is a shortcut for Restrict(RectangleF)
Parameters:
| size (SizeF) | Maxiumum size for the rectangle |
ToString
#Converts this rectangle to a string
Returns: String representation of this rectangle
Overrides: ValueType.ToString
Union
#Combines two rectangles into one rectangle that encompasses both
Parameters:
| rect1 (RectangleF) | First rectangle to union |
| rect2 (RectangleF) | Second rectangle to union |
Returns: A new RectangleF that encompasses both
rect1 and rect2Union
#Union the
rectangle into this instance to encompass both rectanglesParameters:
| rectangle (RectangleF) | Rectangle to union with this instance |
Operators
| Operation | Result | Description | ||
|---|---|---|---|---|
| RectangleF | + | PaddingF | RectangleF | Returns a rectangle inset by the specified padding |
| RectangleF | + | PointF | RectangleF | Adds the offset to the specified rectangle, moving its location |
| RectangleF | + | SizeF | RectangleF | Adds the offset to the specified rectangle, moving its location |
| RectangleF | / | float | RectangleF | Divides all X, Y, Width, Height components of the rectangle by a factor factor |
| RectangleF | / | SizeF | RectangleF | Divides the specified rectangle by the Width and Height of size |
| RectangleF | == | RectangleF | bool | Compares two rectangles for equality |
| RectangleF | != | RectangleF | bool | Compares two rectangles for inequality |
| RectangleF | * | float | RectangleF | Multiplies all X, Y, Width, Height components of the rectangle by a factor |
| RectangleF | * | SizeF | RectangleF | Multiplies the specified rectangle by the Width and Height of size |
| RectangleF | - | PaddingF | RectangleF | Returns a rectangle expanded by the specified padding |
| RectangleF | - | PointF | RectangleF | Subtracts the offset from the specified rectangle, moving its location |
| RectangleF | - | SizeF | RectangleF | Subtracts the offset from the specified rectangle, moving its location |
Convertors
| Operation | Result | Description | ||
|---|---|---|---|---|
| implicit | Rectangle | RectangleF | Implicit conversion from a Rectangle to a RectangleF | |