Specifying Render Objects' Size and Location
The four properties controlling the size and location of a render object are:
• X – specifies the X coordinate of the object.
• Y – specifies the Y coordinate of the object.
• Width – specifies the width of the object.
• Height – specifies the height of the object.
All those properties have the value type C1.C1Preview.Unit. The default value for X and Y is Auto (represented by the static field Unit.Auto), which means that the object is positioned according to the stacking rules provided by its parent (see Stacking above for more information). Width and height have different defaults depending on the type of the render object.
The following table lists the default sizes (width and height) for all render objects, as well as the rules used to calculate auto sizes:
|
Width |
Height |
Auto Size |
RenderArea |
Parent width |
Auto |
Determined by the combined size of the children |
RenderEmpty |
Auto |
Auto |
0 |
RenderGraphics |
Auto |
Auto |
Determined by the size of the content |
RenderImage |
Auto |
Auto |
Determined by the size of the image |
RenderInputButton RenderInputCheckBox RenderInputRadioButton RenderInputComboBox RenderInputText |
Auto |
Auto |
Determined by the size of the content |
RenderRichText |
Parent width (auto width is not supported). |
Auto (determined by the text size). |
-- |
RenderLine RenderPolygon RenderEllipse RenderArc RenderPie RenderRectangle RenderRoundRectangle |
Auto |
Auto |
Determined by the size of the shape |
RenderTable |
Parent width (auto width is calculated as the sum of columns' widths). |
Auto |
Determined by the total width of all columns for width, and by the total height of all rows for height |
RenderParagraph RenderText RenderTocItem |
Parent width |
Auto |
Determined by the size of the text |
RenderField |
Parent width |
Auto |
Determined by the size of the content |
RenderBarCode |
Auto |
Auto |
Determined by the size of the content |
You can override the default values for any of those properties with custom values (specifying anything but Auto as the value for X or Y coordinates excludes the object from the stacking flow; see Stacking for more information). The size and location properties can be set in any of the following ways (note that ro indicates a render object in the samples below):
• As auto (semantics depend on the render object type):
ro.Width = Unit.Auto;
ro.Height = "auto";
• As absolute value:
ro.X = new Unit(8, UnitTypeEnum.Mm);
ro.Y = 8; (C1PrintDocument.DefaultUnit is used for the units);
ro.Width = "28mm";
• As percentage of a parent's size (using this for coordinates is not meaningful and will yield 0):
ro.Height = new Unit(50, DimensionEnum.Width);
ro.Width = "100%";
As a reference to a size or position of another object. The object can be identified by any of the following key words:
self – the current object (the default value, may be omitted);
parent – the object's parent;
prev – the previous sibling;
next – the next sibling;
page – the current page;
column – the current column;
page<N> – page with the specified number (note: the page must already exist, that is forward references to future pages are not supported);
column<M> – a column (specified by number) on the current page;
page<N>.column<N> – a column (specified by number) on the specified page;
<object name> – the object with the specified name (the value of the Name property; the object is searched first among the siblings of the current object, then among its children).
Sizes and locations of the referenced objects are identified by the following key words: left, top, right, bottom, width, height (coordinates are relative to the object's parent).
Some examples:
ro.Height = "next.height"; – sets the object's height to the height of its next sibling;
ro.Width = "page1.width"; – sets the object's width to the width of the first page;
ro.Height = "width"; – sets the object's height to its own width;
ro.Y = "prev.bottom"; – sets the object's Y coordinate to the bottom of its previous sibling;
ro.Width = "prev.width"; – sets the object's width to the width of its previous sibling.
• Using functions "Max" and "Min". For example:
ro.Width = "Max(prev.width,6cm)"; – sets the object's width to the maximum of 6 cm and the object's previous sibling's width;
• As an expression. Expressions can use any of the ways described above to reference size and position of another object, combined using the operators +, -, *, /, %, functions Max and Min, and parentheses ( and ). For example:
ro.Width = "prev.width + 50%prev.width"; – sets the object's width to the width and a half of its previous sibling;
ro.Width = "150%prev"; – same as above (when referencing the same dimension as the one being set, the dimension – "width" in this case – can be omitted).
ro.Width = "prev*1.5"; – again, same as above but using multiplication rather than percentage.
In all of the above samples where a size or location is set to a string, the syntax using the Unit(string) constructor can also be used, for example:
ro.Width = New C1.C1Preview.Unit("150%prev")
• C#
ro.Width = new Unit("150%prev");
Case is not important in strings, so "prev.width", "PrEv.WidTh", and "PREV.WIDTH" are equivalent.
|