# C1.C1Preview.Unit.-ctor

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_C1Preview_Unit__ctor_" data-uid="C1.C1Preview.Unit.#ctor*">Unit Constructor
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_C1Preview_Unit__ctor_" data-uid="C1.C1Preview.Unit.#ctor*"></a>
<h4 id="C1_C1Preview_Unit__ctor_System_String_" data-uid="C1.C1Preview.Unit.#ctor(System.String)">Unit(string)</h4>
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.C1Preview.Unit.html">Unit</a> structure
from a string. See <b>remarks</b> for details.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public Unit(string str)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub New(str As String)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">str</span></td>
      <td><p>A string representing the value.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_C1Preview_Unit__ctor_System_String__remarks">Remarks</h5>
<div class="markdown level1 remarks"><pre><code>&lt;p&gt;(In the description that follows, &lt;b&gt;&quot;object&quot;&lt;/b&gt; means a &lt;xref href=&quot;C1.C1Preview.RenderObject&quot; data-throw-if-not-resolved=&quot;false&quot;&gt;&lt;/xref&gt;
</code></pre>
<p>or another document object on which the current <b>Unit</b> represents a dimension
or a coordinate, not the <b>Unit</b> structure itself.)</p>

<p>The <code class="paramref">str</code> string should contain a valid <a class="xref" href="C1.C1Preview.Unit.html">Unit</a> value
in one of the following forms:</p>
<ul><li>
Auto, represented by the string <b>"auto"</b>.
The exact semantics depend on the type of object with which the current unit is associated.
</li><li>
An unqualified numeric value, e.g. <b>"8"</b> or <b>"100.12"</b>.
<p>In this case <a class="xref" href="C1.C1Preview.C1PrintDocument.DefaultUnit.html#C1_C1Preview_C1PrintDocument_DefaultUnit">DefaultUnit</a> determines the unit of measurement.</p></li><li>
A numeric value qualified with unit of measurement, e.g. <b>"28mm"</b> or <b>"7in"</b>.
<p>The following unit type qualifiers are supported
(for each type, the corresponding element of the <a class="xref" href="C1.C1Preview.UnitTypeEnum.html">UnitTypeEnum</a> enumeration is listed):</p><ul><li><span class="term">def</span><a class="xref" href="C1.C1Preview.C1PrintDocument.DefaultUnit.html#C1_C1Preview_C1PrintDocument_DefaultUnit">DefaultUnit</a> is used
(<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Default">Default</a>; this is equivalent to not specifying untis at all);</li><li><span class="term">doc</span>"Document" units (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Document">Document</a>; 1/300th of an inch);</li><li><span class="term">in</span>Inches (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Inch">Inch</a>);</li><li><span class="term">mm</span>Millimeters (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Mm">Mm</a>);</li><li><span class="term">pc</span>Picas (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Pica">Pica</a>; 1/6 of an inch);</li><li><span class="term">pix</span>Device pixels (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Pixel">Pixel</a>; depend on <a class="xref" href="C1.C1Preview.C1PrintDocument.MeasurementDpi.html#C1_C1Preview_C1PrintDocument_MeasurementDpi">MeasurementDpi</a>);</li><li><span class="term">pt</span>Points (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Point">Point</a>; 1/72 of a inch);</li><li><span class="term">tw</span>Twips (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Twip">Twip</a>; 1/1440 of a inch);</li><li><span class="term">inhs</span>1/100 of an inch (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_InHs">InHs</a>);</li><li><span class="term">dsp</span>"Display" units (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Display">Display</a>; 1/75 of an inch);</li><li><span class="term">cm</span>Centimeters (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Cm">Cm</a>);</li><li><span class="term">em</span>"Em size" (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Em">Em</a>; object font's height);</li><li><span class="term">ex</span>"Ex size" (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_Ex">Ex</a>; object font lowercase <b>x</b>'s height);</li><li><span class="term">ls</span>Object font's line spacing (<a class="xref" href="C1.C1Preview.UnitTypeEnum.html#C1_C1Preview_UnitTypeEnum_LineSpacing">LineSpacing</a>).</li></ul></li><li>
A percentage of the object's parent size, optionally qualified with the parent's dimension
("width" or "height"; if a dimension is not specified, the dimension the current unit referes to is assumed),
e.g. <b>"50%width"</b> or <b>"120%"</b>.
<p>(Percentage can only be used to specify width or height, and is not valid for coordinates.)</p></li><li>
A reference to a dimension or coordinate of another object,
e.g. <b>"prev.width"</b>, <b>"next.bottom"</b> or <b>"page1column2.width"</b>.
<p>The referenced object may be identified by any of the following key words:</p><ul><li><span class="term">self</span>The current object. Default, may be omitted;</li><li><span class="term">parent</span>The current object's parent (container);</li><li><span class="term">prev</span>The previous sibling of the current object;</li><li><span class="term">next</span>The next sibling of the current object;</li><li><span class="term">page</span>The current page;</li><li><span class="term">column</span>The current page column;</li><li><span class="term">page<i>N</i></span>Page by number, <b>N</b> is 1-based
(e.g. <b>"page8"</b>; the page must already exist - forward references using this notation are not supported);</li><li><span class="term">pageindex<i>N</i></span>Page by index, <b>N</b> is 0-based
(e.g. <b>"page0"</b>);</li><li><span class="term">column<i>M</i></span>Column by number, <b>M</b> is 1-based, on the current page (e.g. <b>"column2"</b>);</li><li><span class="term">page<i>N</i>.column<i>M</i></span>Column <b>M</b> on page <b>N</b>, <b>M</b> and <b>N</b> are 1-based (e.g. <b>"page8.column2"</b>);</li><li><span class="term"><i>object name</i></span>Object with the specified name (see <a class="xref" href="C1.C1Preview.RenderObject.Name.html#C1_C1Preview_RenderObject_Name">Name</a>).
The object is first searched among the siblings of the current object, then among its children.</li></ul>
<p>The referenced dimension or coordinate may be specified using any of the following key words:</p>
<ul><li><span class="term">left</span>The <b>X</b> coordinate of the left edge of an object;</li><li><span class="term">top</span>The <b>Y</b> coordinate of the top edge of an object;</li><li><span class="term">right</span>The <b>X</b> coordinate of the right edge of an object;</li><li><span class="term">bottom</span>The <b>Y</b> coordinate of the bottom edge of an object;</li><li><span class="term">width</span>The width of an object;</li><li><span class="term">height</span>The height of an object.</li></ul></li><li>
A <b>Max</b> or <b>Min</b> built-in function call, e.g. <b>"Max(prev.width,6cm)"</b> or <b>"Min(0.5in,next.height)"</b>.
</li><li>
An expression using operands in any of the forms described above (except <b>"auto"</b>),
combined using operators <b>+</b> (add), <b>-</b> (subtract), <b>*</b> (multiply), <b>/</b> (divide), <b>%</b> (percent),
functions <b>Min</b> and <b>Max</b>, and parentheses <b>(</b> and <b>)</b>.
<p>Examples of unit expressions are:</p><ul><li><span class="term">prev.width + 50%prev.width</span>This expression can be used to specify the width of an object being 1.5 times the width of its previous sibling</li><li><span class="term">150%prev</span>Same as above</li><li><span class="term">prev * 1.5</span>Same as above but using multiplication instead of percentage</li></ul></li></ul>
</div>


<a id="C1_C1Preview_Unit__ctor_" data-uid="C1.C1Preview.Unit.#ctor*"></a>
<h4 id="C1_C1Preview_Unit__ctor_System_Double_C1_C1Preview_UnitTypeEnum_" data-uid="C1.C1Preview.Unit.#ctor(System.Double,C1.C1Preview.UnitTypeEnum)">Unit(double, UnitTypeEnum)</h4>
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.C1Preview.Unit.html">Unit</a> structure
with an absolute length value.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public Unit(double value, UnitTypeEnum unitType)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub New(value As Double, unitType As UnitTypeEnum)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.double">double</a></td>
      <td><span class="parametername">value</span></td>
      <td><p>The unit value.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="C1.C1Preview.UnitTypeEnum.html">UnitTypeEnum</a></td>
      <td><span class="parametername">unitType</span></td>
      <td><p>The unit of measurement.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
