[TypeConverter(SizeConverterInternal)] public struct Size : IEquatable<Size>
Represents a size with width and height components

Constructors

Size

#Since v2.14
public Size(int size)
Initializes a new Size class with an identical width and height

Size

#
public Size(int width, int height)
Initializes a new Size class with the specified width and height
width (int)Initial width of the size
height (int)Initial height of the size

Size

#
public Size(Point point)
Initializes a new Size class with width and height corresponding to the Point.X and Point.Y of the specified point

Size

#
public Size(SizeF size)
Initializes a new Size with the truncated width and height of size.

Fields

Empty

#
public static readonly Size Empty
Gets an empty size with a zero width and height

MaxValue

#
public static readonly Size MaxValue
Size with width and height with a maximum int value

MinValue

#
public static readonly Size MinValue
Size with width and height with a minimum int value

Properties

Methods

Abs

#
public static Size Abs(Size size)
Returns the absolute width and height of the specified size
size (Size)Size to convert
A new instance of a Size struct with absolute (positive) width and height

Ceiling

#
public static Size Ceiling(SizeF size)
Converts a floating point size to an integral size by rounding the width and height to the next integral value.
Remarks: This is useful to get a size struct that includes the floating point values completely. As opposed to the Round(SizeF), which will round down to the nearest integral number. For example, a Width or Height of 2.1 or 2.6 would be translated to 3.
size (SizeF)Size.

Contains

#
public bool Contains(int x, int y)
Gets a value indicating that the specified x and y values are within the Width and Height of this size
x (int)X value to test
y (int)Y value to test
True if the x and y values are greater than or equal to 0 and less than the Width and Height of this size, respectively. False otherwise

Contains

#
public bool Contains(Point point)
Gets a value indicating that the specified point is within the Width and Height of this size
point (Point)Point to test
True if the point has an X and Y value between 0 and the Width and Height of this size, respectively. False otherwise

Equals

#
public override bool Equals(object obj)
Compares this size to the specified obj
obj (object)Object to compare with
True if the specified obj is a Size and is equal to this instance
ValueType.Equals

Equals

#
public bool Equals(Size other)
Compares this size to the other size
other (Size)Other size to compare with
True if the other size is equal to this instance

FitTo

#
public Size FitTo(Size constraint)
Fits this size to the specified constraint, keeping the aspect
constraint (Size)Constraint to fit the new size into
The new size with the same aspect ratio with the width/height equal or within the constraint

GetHashCode

#
public override int GetHashCode()
Gets the hash code for this Size

Max

#
public static Size Max(Size size1, Size size2)
Returns the maximum width and height of two sizes
size1 (Size)First size to get the maximum values
size2 (Size)Second size to get the maximum values
A new instance of a Size struct with the maximum width and height of either sizes

Min

#
public static Size Min(Size size1, Size size2)
Returns the minimum width and height of two sizes
size1 (Size)First size to get the minimum values
size2 (Size)Second size to get the minimum values
A new instance of a Size struct with the minimum width and height of either sizes

Round

#
public static Size Round(SizeF size)
Converts a floating point size to an integral size by rounding the width and height
size (SizeF)Size to convert
A new instance of a Size class with rounded width and height values of the specified size

ToString

#
public override string ToString()
Converts this Size struct to a string

Truncate

#
public static Size Truncate(SizeF size)
Converts a floating point size to an integral size by truncating the width and height
size (SizeF)Size to convert
A new instance of a Size struct with truncated width and height values of the specified size

Operators

OperationResultDescription
Size+intSizeAdds a value to the Width and Height of the specified size
Size+PointSizeAdds the Point.X and Point.Y value to the Width and Height of a size
Size+SizeSizeAdds the Width and Height values of two sizes together
Size/intSizeDivides the Width and Height of a size by the specified factor
Size/SizeSizeDivides the Width and Height of two sizes
Size==SizeboolCompares two sizes for equality
Size!=SizeboolCompares two sizes for inequality
int*SizeSizeMultiplies the Width and Height of a size by the specified factor
Size*intSizeMultiplies the Width and Height of a size by the specified factor
Size*SizeSizeMultiplies the Width and Height of two sizes
Size*floatSizeFMultiplies the Width and Height of a size by the specified floating point factor
Size-intSizeSubtracts a value from the Width and Height of the specified size
Size-PointSizeSubtracts the Point.X and Point.Y value from the Width and Height of a size
Size-SizeSizeSubtracts the Width and Height value of one size from another
-SizeSizeNegates the Width and Height of the specified size value

Convertors

OperationResultDescription
explicitPointSizeExplicit conversion from a point to a Size with a Width and Height of the X and Y values of the point, respectively
explicitSizeFSizeExplicit conversion from a SizeF to a Size by truncating values