Struct Thickness
- Namespace
- Myra.Graphics2D
- Assembly
- Myra.dll
Represents the thicknesses of the four sides of a rectangle (left, right, top, bottom).
public struct Thickness
- Inherited Members
Constructors
Thickness(int)
Initializes a new instance of the Thickness struct with the same value for all sides.
public Thickness(int value)
Parameters
valueintThe thickness for all sides.
Thickness(int, int)
Initializes a new instance of the Thickness struct with separate horizontal and vertical values.
public Thickness(int horizontalValue, int verticalValue)
Parameters
horizontalValueintThe thickness for left and right sides.
verticalValueintThe thickness for top and bottom sides.
Thickness(int, int, int, int)
Initializes a new instance of the Thickness struct with individual values for each side.
public Thickness(int left, int top, int right, int bottom)
Parameters
leftintThe left thickness.
topintThe top thickness.
rightintThe right thickness.
bottomintThe bottom thickness.
Fields
Zero
Gets a thickness with all values set to zero.
public static readonly Thickness Zero
Field Value
Properties
Bottom
Gets or sets the bottom thickness.
[Range(0)]
public int Bottom { get; set; }
Property Value
Height
Gets the total vertical thickness (top + bottom).
[Browsable(false)]
public int Height { get; }
Property Value
Left
Gets or sets the left thickness.
[Range(0)]
public int Left { get; set; }
Property Value
Right
Gets or sets the right thickness.
[Range(0)]
public int Right { get; set; }
Property Value
SameSize
Gets a value indicating whether all sides have the same thickness.
[Browsable(false)]
public bool SameSize { get; }
Property Value
Top
Gets or sets the top thickness.
[Range(0)]
public int Top { get; set; }
Property Value
Width
Gets the total horizontal thickness (left + right).
[Browsable(false)]
public int Width { get; }
Property Value
Methods
Equals(object)
Determines whether the specified object is equal to the current thickness.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current thickness.
Returns
- bool
True if the specified object is equal to the current thickness; otherwise, false.
FromString(string)
Parses a thickness value from a string.
public static Thickness FromString(string s)
Parameters
sstringThe string to parse.
Returns
- Thickness
The parsed thickness, or Zero if the string is null or empty.
Remarks
Supported formats: "5" (all sides), "5, 10" (horizontal, vertical), "1, 2, 3, 4" (left, top, right, bottom).
Exceptions
- ArgumentException
The string format is invalid.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer hash code.
ToString()
Returns a string representation of the thickness.
public override string ToString()
Returns
- string
A string representation in the format "value", "h, v", or "l, t, r, b".
Operators
operator ==(Thickness, Thickness)
Determines whether two thickness values are equal.
public static bool operator ==(Thickness a, Thickness b)
Parameters
Returns
- bool
True if the two thickness values are equal; otherwise, false.
operator !=(Thickness, Thickness)
Determines whether two thickness values are not equal.
public static bool operator !=(Thickness a, Thickness b)
Parameters
Returns
- bool
True if the two thickness values are not equal; otherwise, false.
operator -(Rectangle, Thickness)
Subtracts the thickness from a rectangle.
public static Rectangle operator -(Rectangle a, Thickness b)
Parameters
aRectangleThe rectangle to subtract from.
bThicknessThe thickness to subtract.
Returns
- Rectangle
A new rectangle with the thickness applied, shrinking the rectangle.