VegaRise.NET

DocumentUnit

DocumentUnit is the measurement type used across all layout, sizing and spacing properties. It stores values internally as EMUs and exposes getters/setters in points, inches, cm, mm, twips, pixels, and percentages.

C#
1using Vega.DOM;
2using DOM.Enums;
3
4// Implicit conversion from double is interpreted as points.
5DocumentUnit width = 12.0;
6double? inches = width.Inch;
7
8var fromCm = new DocumentUnit(2.54, Units.cm);
9var fromTwips = new DocumentUnit(1440, Units.Twips);
10var fromEmu = new DocumentUnit(127000L); // long -> EMU
11
12// Set and read individual units
13var u = new DocumentUnit();
14u.Point = 11.0;
15Console.WriteLine(u.MM); // ~3.88
16Console.WriteLine(u.PX); // ~15
17
18// Use anywhere a measurement is expected
19var border = new BorderStyle
20{
21 BorderSize = 2.5, // 2.5 points
22 BorderSpace = new DocumentUnit(0.1, Units.inch),
23};

Frequently asked questions

What does the implicit conversion from double mean?

A plain double is treated as points. Use new DocumentUnit(value, unit) to be explicit about other units.

How do I represent a relative value?

Use the Percentage type or set DocumentUnit.Percentage.

VegaRiseVDocs.NET

Create Account

Create your VDocs account.

or

Already have an account? Sign in