[]
A utility structure specifying some values related to units of measurement.
public struct Unit
Initializes a new instance of the Unit structure.
public Unit(float value, UnitTypeEnum unitType)
value
floatThe unit value.
unitType
UnitTypeEnumThe unit of measurement.
Initializes a new instance of the Unit structure from a string. String should contain A numeric value qualified with unit of measurement, e.g. "28mm" or "7in".
public Unit(string str)
str
stringCentimeters per inch as double.
public const float CmPerInch = 2.54
DIP units per inch as double.
public const float DipPerInch = 96
Display units per inch as double.
public const float DisplayPerInch = 75
Document units per inch as double.
public const float DocumentUnitsPerInch = 300
Millimeters per inch as double.
public const float MmPerInch = 25.4
Picas per inch as double.
public const float PicaPerInch = 6
Points per inch as double.
public const float PointsPerInch = 72
Twips per inch as double.
public const float TwipsPerInch = 1440
Represents "0mm" value.
public static readonly Unit Zero
Gets the unit of measurement of the current unit.
public UnitTypeEnum Units { get; }
Gets the value of the current unit (in Units).
public float Value { get; }
Converts value of this Unit structure to value in specified units of measurement.
public float Convert(UnitTypeEnum to)
to
UnitTypeEnumThe target unit of measurement.
Returns the value in to
units.
Converts a value from one unit of measurement to another.
public static float Convert(float value, UnitTypeEnum from, UnitTypeEnum to)
value
floatThe value to convert.
from
UnitTypeEnumThe source unit of measurement.
to
UnitTypeEnumThe target unit of measurement.
value
converted to to
units.
Converts a value from one unit of measurement to pixel.
public static float Convert(float value, UnitTypeEnum from, float toDpi)
value
floatThe value to convert in from
units.
from
UnitTypeEnumThe source unit of measurement.
toDpi
floatThe target dpi.
value
converted to pixels with specified dpi.
Converts a value from pixel unit of measurement to another.
public static float Convert(float value, float fromDpi, UnitTypeEnum to)
value
floatThe value to convert in pixels.
fromDpi
floatThe source dpi.
to
UnitTypeEnumThe target unit of measurement.
value
converted to to
units.
Parses a string and creates a Unit instance from that string, throws an exception if string is invalid.
public static Unit Parse(string s)
s
stringThe string to parse.
Converts a string to a UnitTypeEnum value. The string can be one of the following: "doc", "in", "mm", "pc", "dsp", "pt", "tw", "inhs", "cm", "dip". This method is case-insensitive.
public static bool StringToUnitType(string s, ref UnitTypeEnum value)
s
stringThe string to convert.
value
UnitTypeEnumOUT: On exit, contains the UnitTypeEnum value.
true if no error occurred, false otherwise.
Converts the current object to a string.
public override string ToString()
The string representing the current Unit object.
Parses a string and creates Unit structure.
public static bool TryParse(string s, out Unit unit)
True if the conversion was successfull, false otherwise.
public static bool TryParse(string s, out float value, out UnitTypeEnum units)
s
stringThe string to parse.
value
floatOUT: value of Unit structure.
units
UnitTypeEnumOUT: units of Unit structure.
A true if conversion was successfull.
Converts a UnitTypeEnum value to a string representation as in the following table:
public static string UnitTypeToString(UnitTypeEnum value)
value
UnitTypeEnumA UnitTypeEnum to convert.
The string representing value
.
Converts a unit value to a string.
public static implicit operator string(Unit value)
value
UnitThe unit to convert.
The string representing the unit value.
Converts a string to a Unit value (see Unit(string).
public static implicit operator Unit(string value)
value
stringThe string to convert.
The unit value.