Struct RectangleF
Stores a set of four floating-point numbers that represent the location and size of a rectangle.
public struct RectangleF
- Inherited Members
Constructors
RectangleF(PointF, SizeF)
Initializes a new instance of the RectangleF structure with the specified location and size.
public RectangleF(PointF location, SizeF size)
Parameters
location
PointFA PointF that represents the upper-left corner of the rectangular region.
size
SizeFA SizeF that represents the width and height of the rectangular region.
RectangleF(float, float, float, float)
Initializes a new instance of the RectangleF structure with the specified location and size.
public RectangleF(float x, float y, float width, float height)
Parameters
x
floatThe x-coordinate of the upper-left corner of the rectangle.
y
floatThe y-coordinate of the upper-left corner of the rectangle.
width
floatThe width of the rectangle.
height
floatThe height of the rectangle.
Properties
Bottom
Gets or sets the y-coordinate that is the sum of Y and Height of this RectangleF structure.
public float Bottom { get; set; }
Property Value
- float
The y-coordinate that is the sum of Y and Height of this RectangleF structure.
Empty
Gets a new instance of the RectangleF structure that has X, Y, Width and Height values set to zero.
public static RectangleF Empty { get; }
Property Value
Height
Gets or sets the height of this RectangleF structure.
public float Height { get; set; }
Property Value
- float
The height of this RectangleF structure.
IsEmpty
Gets a value indicating whether the Width or Height property of this RectangleF has a value of zero.
public bool IsEmpty { get; }
Property Value
- bool
This property returns true if the Width or Height property of this RectangleF has a value of zero; otherwise, false.
Left
Gets or sets the x-coordinate of the left edge of this RectangleF structure.
public float Left { get; set; }
Property Value
- float
The x-coordinate of the left edge of this RectangleF structure.
Location
Gets or sets the coordinates of the upper-left corner of this RectangleF structure.
public PointF Location { get; set; }
Property Value
- PointF
A PointF that represents the upper-left corner of this RectangleF structure.
Right
Gets or sets the x-coordinate that is the sum of X and Width of this RectangleF structure.
public float Right { get; set; }
Property Value
- float
The x-coordinate that is the sum of X and Width of this RectangleF structure.
Size
Gets or sets the size of this RectangleF.
public SizeF Size { get; set; }
Property Value
- SizeF
A SizeF that represents the width and height of this RectangleF structure.
Top
Gets or sets the y-coordinate of the top edge of this RectangleF structure.
public float Top { get; set; }
Property Value
- float
The y-coordinate of the top edge of this RectangleF structure.
Width
Gets or sets the width of this RectangleF structure.
public float Width { get; set; }
Property Value
- float
The width of this RectangleF structure.
X
Gets or sets the x-coordinate of the upper-left corner of this RectangleF structure.
public float X { get; set; }
Property Value
- float
The x-coordinate of the upper-left corner of this RectangleF structure.
Y
Gets or sets the y-coordinate of the upper-left corner of this RectangleF structure.
public float Y { get; set; }
Property Value
- float
The y-coordinate of the upper-left corner of this RectangleF structure.
Methods
Contains(PointF)
Determines if the specified point is contained within this RectangleF structure.
public bool Contains(PointF point)
Parameters
Returns
- bool
This method returns true if the point represented by the
point
parameter is contained within this RectangleF structure; otherwise false.
Contains(RectangleF)
Determines if the rectangular region represented by rect
is entirely contained within this RectangleF structure.
public bool Contains(RectangleF rect)
Parameters
rect
RectangleFThe RectangleF to test.
Returns
- bool
This method returns true if the rectangular region represented by
rect
is entirely contained within the rectangular region represented by this RectangleF; otherwise false.
Contains(float, float)
Determines if the specified point is contained within this RectangleF structure.
public bool Contains(float x, float y)
Parameters
Returns
- bool
This method returns true if the point defined by
x
andy
is contained within this RectangleF structure; otherwise false.
Equals(object)
Tests whether obj
is a RectangleF with the same location and size of this RectangleF.
public override bool Equals(object obj)
Parameters
Returns
- bool
This method returns true if
obj
is a RectangleF and its X, Y, Width, and Height properties are equal to the corresponding properties of this RectangleF; otherwise, false.
FromLeftTopRightBottom(float, float, float, float)
Creates a RectangleF structure with upper-left corner and lower-right corner at the specified locations.
public static RectangleF FromLeftTopRightBottom(float left, float top, float right, float bottom)
Parameters
left
floatThe x-coordinate of the upper-left corner of the rectangular region.
top
floatThe y-coordinate of the upper-left corner of the rectangular region.
right
floatThe x-coordinate of the lower-right corner of the rectangular region.
bottom
floatThe y-coordinate of the lower-right corner of the rectangular region.
Returns
- RectangleF
The new RectangleF that this method creates.
FromPoints(PointF, PointF)
Creates a new Rectangle from two points specified. Two verticles of the created Rectangle will be equal to the passed point1
and point2
. These would be typically the opposite vertices.
public static RectangleF FromPoints(PointF point1, PointF point2)
Parameters
point1
PointFThe first Point for the new rectangle.
point2
PointFThe second Point for the new rectangle.
Returns
- RectangleF
A newly created Rectangle.
GetHashCode()
Gets the hash code for this RectangleF structure.
public override int GetHashCode()
Returns
- int
The hash code for this RectangleF.
Inflate(RectangleF, float, float)
Creates and returns an inflated copy of the specified RectangleF structure. The copy is inflated by the specified amount. The original rectangle remains unmodified.
public static RectangleF Inflate(RectangleF rect, float x, float y)
Parameters
rect
RectangleFThe RectangleF to be copied. This rectangle is not modified.
x
floatThe amount to inflate the copy of the rectangle horizontally.
y
floatThe amount to inflate the copy of the rectangle vertically.
Returns
- RectangleF
The inflated RectangleF.
Inflate(SizeF)
Inflates this RectangleF by the specified amount.
public void Inflate(SizeF size)
Parameters
size
SizeFThe amount to inflate this rectangle.
Inflate(float, float)
Inflates this RectangleF structure by the specified amount.
public void Inflate(float x, float y)
Parameters
x
floatThe amount to inflate this RectangleF structure horizontally.
y
floatThe amount to inflate this RectangleF structure vertically.
Intersect(RectangleF)
Replaces this RectangleF structure with the intersection of itself and the specified RectangleF structure.
public void Intersect(RectangleF rect)
Parameters
rect
RectangleFThe rectangle to intersect.
Intersect(RectangleF, RectangleF)
Returns a RectangleF structure that represents the intersection of two rectangles. If there is no intersection, and empty RectangleF is returned.
public static RectangleF Intersect(RectangleF a, RectangleF b)
Parameters
a
RectangleFA first rectangle to intersect.
b
RectangleFA second rectangle to intersect.
Returns
- RectangleF
A third RectangleF structure the size of which represents the overlapped area of the two specified rectangles.
IntersectsWith(RectangleF)
Determines if this rectangle intersects with rect
.
public bool IntersectsWith(RectangleF rect)
Parameters
rect
RectangleFThe rectangle to test.
Returns
- bool
This method returns true if there is any intersection.
Normalize()
Normalizes the rectangle by making it's width and height positive, left less than right and top less than bottom.
public void Normalize()
Offset(PointF)
Adjusts the location of this rectangle by the specified amount.
public void Offset(PointF pos)
Parameters
pos
PointFThe amount to offset the location.
Offset(float, float)
Adjusts the location of this rectangle by the specified amount.
public void Offset(float x, float y)
Parameters
x
floatThe amount to offset the location horizontally.
y
floatThe amount to offset the location vertically.
ToString()
Converts the attributes of this RectangleF to a human-readable string.
public override string ToString()
Returns
- string
A string that contains the position, width, and height of this RectangleF structure.
Union(RectangleF, RectangleF)
Creates the smallest possible third rectangle that can contain both of two rectangles that form a union.
public static RectangleF Union(RectangleF a, RectangleF b)
Parameters
a
RectangleFA first rectangle to union.
b
RectangleFA second rectangle to union.
Returns
- RectangleF
A third RectangleF structure that contains both of the two rectangles that form the union.
Operators
operator /(RectangleF, float)
Implements the operator /.
public static RectangleF operator /(RectangleF rectangle, float divider)
Parameters
rectangle
RectangleFThe rectangle.
divider
floatThe divider.
Returns
- RectangleF
The result of the operator.
Exceptions
- ArgumentOutOfRangeException
divider - Division by zero is not allowed.
operator ==(RectangleF, RectangleF)
Tests whether two RectangleF structures have equal location and size.
public static bool operator ==(RectangleF left, RectangleF right)
Parameters
left
RectangleFThe RectangleF structure that is to the left of the equality operator.
right
RectangleFThe RectangleF structure that is to the right of the equality operator.
Returns
- bool
This operator returns true if the two specified RectangleF structures have equal X, Y, Width, and Height properties.
implicit operator RectangleF(Rectangle)
Converts the specified Rectangle structure to a RectangleF structure.
public static implicit operator RectangleF(Rectangle rect)
Parameters
Returns
- RectangleF
The RectangleF structure that is converted from the specified Rectangle structure.
operator !=(RectangleF, RectangleF)
Tests whether two RectangleF structures differ in location or size.
public static bool operator !=(RectangleF left, RectangleF right)
Parameters
left
RectangleFThe RectangleF structure that is to the left of the inequality operator.
right
RectangleFThe RectangleF structure that is to the right of the inequality operator.
Returns
- bool
This operator returns true if any of the X , Y, Width, or Height properties of the two RectangleF structures are unequal; otherwise false.
operator *(RectangleF, float)
Implements the operator *.
public static RectangleF operator *(RectangleF rectangle, float multiplier)
Parameters
rectangle
RectangleFThe rectangle.
multiplier
floatThe multiplier.
Returns
- RectangleF
The result of the operator.