<PackageReference Include="System.Drawing.Common" Version="10.0.0-preview.3.25173.2" />

Margins

public class Margins : ICloneable
Specifies the dimensions of the margins of a printed page.
using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.Serialization; namespace System.Drawing.Printing { [NullableContext(1)] [Nullable(0)] [TypeConverter(typeof(MarginsConverter))] public class Margins : ICloneable { private int _left; private int _right; private int _bottom; private int _top; [OptionalField] private double _doubleLeft; [OptionalField] private double _doubleRight; [OptionalField] private double _doubleTop; [OptionalField] private double _doubleBottom; public int Left { get { return _left; } set { CheckMargin(value, "value"); _left = value; _doubleLeft = (double)value; } } public int Right { get { return _right; } set { CheckMargin(value, "value"); _right = value; _doubleRight = (double)value; } } public int Top { get { return _top; } set { CheckMargin(value, "value"); _top = value; _doubleTop = (double)value; } } public int Bottom { get { return _bottom; } set { CheckMargin(value, "value"); _bottom = value; _doubleBottom = (double)value; } } internal double DoubleLeft { get { return _doubleLeft; } set { Left = (int)Math.Round(value); _doubleLeft = value; } } internal double DoubleRight { get { return _doubleRight; } set { Right = (int)Math.Round(value); _doubleRight = value; } } internal double DoubleTop { get { return _doubleTop; } set { Top = (int)Math.Round(value); _doubleTop = value; } } internal double DoubleBottom { get { return _doubleBottom; } set { Bottom = (int)Math.Round(value); _doubleBottom = value; } } public Margins() : this(100, 100, 100, 100) { } public Margins(int left, int right, int top, int bottom) { CheckMargin(left, "left"); CheckMargin(right, "right"); CheckMargin(top, "top"); CheckMargin(bottom, "bottom"); _left = left; _right = right; _top = top; _bottom = bottom; _doubleLeft = (double)left; _doubleRight = (double)right; _doubleTop = (double)top; _doubleBottom = (double)bottom; } private static void CheckMargin(int margin, string name) { if (margin < 0) throw new ArgumentOutOfRangeException(name, margin, System.SR.Format(System.SR.InvalidLowBoundArgumentEx, name, margin, 0)); } public object Clone() { return MemberwiseClone(); } [NullableContext(2)] public override bool Equals([NotNullWhen(true)] object obj) { Margins margins = obj as Margins; if ((object)margins != null && margins.Left == Left && margins.Right == Right && margins.Top == Top) return margins.Bottom == Bottom; return false; } public override int GetHashCode() { return HashCode.Combine(Left, Right, Top, Bottom); } public static bool operator ==(Margins m1, Margins m2) { if ((object)m1 == null) return (object)m2 == null; if ((object)m2 == null) return false; return m1.Equals(m2); } public static bool operator !=(Margins m1, Margins m2) { return !(m1 == m2); } public override string ToString() { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(35, 4); defaultInterpolatedStringHandler.AppendLiteral("[Margins Left="); defaultInterpolatedStringHandler.AppendFormatted(Left); defaultInterpolatedStringHandler.AppendLiteral(" Right="); defaultInterpolatedStringHandler.AppendFormatted(Right); defaultInterpolatedStringHandler.AppendLiteral(" Top="); defaultInterpolatedStringHandler.AppendFormatted(Top); defaultInterpolatedStringHandler.AppendLiteral(" Bottom="); defaultInterpolatedStringHandler.AppendFormatted(Bottom); defaultInterpolatedStringHandler.AppendLiteral("]"); return defaultInterpolatedStringHandler.ToStringAndClear(); } } }