Struct Margin
- Namespace
- Northwoods.Go
- Assembly
- Northwoods.GoDiagram.WinForms.dll
A Margin represents a band of space outside or inside a rectangular area, with possibly different values on each of the four sides.
public struct Margin
- Inherited Members
Remarks
Example uses include Margin, Padding, and Padding.
Use the static functions Parse(string) and Stringify(Margin) to convert to and from a standard string representation that is independent of the current locale.
Constructors
Margin(double)
Create a Margin with all four sides using the same number.
public Margin(double s = 0)
Parameters
s
doublethe margin for all four sides, defaults to 0
Margin(double, double)
Create a Margin with the top and bottom getting the first parameter and the left and right getting the second.
public Margin(double tb, double rl)
Parameters
Margin(double, double, double, double)
Create a Margin with each side getting the corresponding parameter in the order top, right, bottom, left.
public Margin(double t, double r, double b, double l)
Parameters
t
doublethe margin for the top side
r
doublethe margin for the right side
b
doublethe margin for the bottom side
l
doublethe margin for the left side
Properties
Bottom
Gets or sets the bottom value of this margin. Default is 0.
public double Bottom { readonly get; set; }
Property Value
Left
Gets or sets the left value of this margin. Default is 0.
public double Left { readonly get; set; }
Property Value
Right
Gets or sets the right value of this margin. Default is 0.
public double Right { readonly get; set; }
Property Value
Top
Gets or sets the top value of this margin. Default is 0.
public double Top { readonly get; set; }
Property Value
Methods
Equals(double, double, double, double)
Indicates whether the given Margin is equal to this Margin.
public bool Equals(double t, double r, double b, double l)
Parameters
Returns
- bool
True if the two Margins have identical Top and Right and Bottom and Left values, false otherwise.
- See Also
Equals(object)
Indicates whether the given Margin is equal to this Margin.
public override bool Equals(object obj)
Parameters
obj
objectThe Margin to compare to the current Margin.
Returns
- bool
True if the two Margins have identical Top and Right and Bottom and Left values, false otherwise.
- See Also
EqualsApprox(Margin)
Indicates whether the given Margin is nearly equal to this Margin.
public bool EqualsApprox(Margin m)
Parameters
m
MarginThe Margin to compare to the current Margin.
Returns
- bool
True if the two Margins have Top, Right, Bottom and Left values within 0.5, false otherwise.
GetHashCode()
Creates a hash code for the margin.
public override int GetHashCode()
Returns
- int
A hash code for the current margin structure.
IsReal()
True if this Margin has values that are real numbers and not infinity.
public bool IsReal()
Returns
Parse(object)
This is a convenience method for Parse(string) that can be used as a Converter.
public static object Parse(object str)
Parameters
str
object
Returns
Parse(string)
This static method can be used to read in a Margin from a string that was produced by Stringify(Margin).
public static Margin Parse(string str)
Parameters
str
string
Returns
Remarks
Margin.Parse("1 2 3 4")
produces the Margin new Margin(1, 2, 3, 4)
. This function will throw an error on invalid strings.
Stringify(Margin)
This static method can be used to write out a Margin as a string that can be read by Parse(string).
public static string Stringify(Margin val)
Parameters
val
Margin
Returns
Remarks
Margin.Stringify(new Margin(1, 2, 3, 4))
produces the string "1 2 3 4".
Stringify(object)
This is a convenience method for Stringify(Margin) that can be used as a BackConverter.
public static object Stringify(object marg)
Parameters
marg
object
Returns
StringifyFixed(Margin, int)
This static method can be used to write out a Margin as a string with its numbers at a fixed number of digits after the decimal point.
public static string StringifyFixed(Margin val, int digits)
Parameters
Returns
Remarks
This is useful for limiting the size of JSON output and making it more legible. It might also be useful for regression testing.
StringifyFixed(object)
This is a convenience method for StringifyFixed(Margin, int) that can be used as a BackConverter. This convenience method uses two decimal places.
public static object StringifyFixed(object marg)
Parameters
marg
object
Returns
ToString()
Returns a string representation of the margin.
public override string ToString()
Returns
- string
A string representation of the current margin.
Operators
operator ==(Margin, Margin)
public static bool operator ==(Margin left, Margin right)
Parameters
Returns
implicit operator Margin(double)
public static implicit operator Margin(double d)
Parameters
d
double
Returns
implicit operator Margin(int)
public static implicit operator Margin(int d)
Parameters
d
int
Returns
operator !=(Margin, Margin)
public static bool operator !=(Margin left, Margin right)