Struct Margin

GoDiagram®
v10.0.11
by Northwoods Software®

A Margin represents a band of space outside or inside a rectangular area, with possibly different values on each of the four sides.

Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.Avalonia.dll
Syntax
public struct Margin
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, double, double, double)

Create a Margin with each side getting the corresponding parameter in the order top, right, bottom, left.

Declaration
public Margin(double t, double r, double b, double l)
Parameters
Type Name Description
double t

the margin for the top side

double r

the margin for the right side

double b

the margin for the bottom side

double l

the margin for the left side

Margin(double, double)

Create a Margin with the top and bottom getting the first parameter and the left and right getting the second.

Declaration
public Margin(double tb, double rl)
Parameters
Type Name Description
double tb

the margin for the top and bottom sides

double rl

the margin for the right and left sides

Margin(double)

Create a Margin with all four sides using the same number.

Declaration
public Margin(double s = 0)
Parameters
Type Name Description
double s

the margin for all four sides, defaults to 0

Properties

Bottom

Gets or sets the bottom value of this margin. Default is 0.

Declaration
public double Bottom { readonly get; set; }
Property Value
Type Description
double

Left

Gets or sets the left value of this margin. Default is 0.

Declaration
public double Left { readonly get; set; }
Property Value
Type Description
double

Right

Gets or sets the right value of this margin. Default is 0.

Declaration
public double Right { readonly get; set; }
Property Value
Type Description
double

Top

Gets or sets the top value of this margin. Default is 0.

Declaration
public double Top { readonly get; set; }
Property Value
Type Description
double

Methods

Equals(double, double, double, double)

Indicates whether the given Margin is equal to this Margin.

Declaration
public bool Equals(double t, double r, double b, double l)
Parameters
Type Name Description
double t

top.

double r

right.

double b

bottom.

double l

left.

Returns
Type Description
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.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
object obj

The Margin to compare to the current Margin.

Returns
Type Description
bool

True if the two Margins have identical Top and Right and Bottom and Left values, false otherwise.

Overrides
See Also

EqualsApprox(Margin)

Indicates whether the given Margin is nearly equal to this Margin.

Declaration
public bool EqualsApprox(Margin m)
Parameters
Type Name Description
Margin m

The Margin to compare to the current Margin.

Returns
Type Description
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.

Declaration
public override int GetHashCode()
Returns
Type Description
int

A hash code for the current margin structure.

Overrides

IsReal()

True if this Margin has values that are real numbers and not infinity.

Declaration
public bool IsReal()
Returns
Type Description
bool

Parse(object)

This is a convenience method for Parse(string) that can be used as a Converter.

Declaration
public static object Parse(object str)
Parameters
Type Name Description
object str
Returns
Type Description
object

Parse(string)

This static method can be used to read in a Margin from a string that was produced by Stringify(Margin).

Declaration
public static Margin Parse(string str)
Parameters
Type Name Description
string str
Returns
Type Description
Margin
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).

Declaration
public static string Stringify(Margin val)
Parameters
Type Name Description
Margin val
Returns
Type Description
string
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.

Declaration
public static object Stringify(object marg)
Parameters
Type Name Description
object marg
Returns
Type Description
object

ToString()

Returns a string representation of the margin.

Declaration
public override string ToString()
Returns
Type Description
string

A string representation of the current margin.

Overrides

Operators

operator ==(Margin, Margin)

Declaration
public static bool operator ==(Margin left, Margin right)
Parameters
Type Name Description
Margin left
Margin right
Returns
Type Description
bool

implicit operator Margin(double)

Declaration
public static implicit operator Margin(double d)
Parameters
Type Name Description
double d
Returns
Type Description
Margin

implicit operator Margin(int)

Declaration
public static implicit operator Margin(int d)
Parameters
Type Name Description
int d
Returns
Type Description
Margin

operator !=(Margin, Margin)

Declaration
public static bool operator !=(Margin left, Margin right)
Parameters
Type Name Description
Margin left
Margin right
Returns
Type Description
bool