Styles in Tables
To further facilitate their use, some additional style features specific to tables are introduced. Most importantly, in addition to Style, styles of render objects that are table elements (which include the whole table, table header, footer and body, rows, columns and cells) contain one more property of the type C1DocStyle, StyleTableCell, that is used only when rendering table cells. Here is how it works:
• Outside of tables, StyleTableCell is not available.
• When a table is created, its StyleTableCell is created and inherits from the root document style. Inside that table (that is, for its body, header, footer, and all rows, columns and cells contained inside), inheritance rules for StyleTableCell properties of those objects change, and StyleTableCell styles' hierarchy follows the hierarchy of the table elements. For example, when a table body is created, its StyleTableCell's parent is the StyleTableCell of the table. When a row is added to the body, its StyleTableCell has the same StyleTableCell of the body as the parent, and so on.
• When rendering any table elements except cells, the StyleTableCell is not actually used. For example, shading of a table row is controlled by its row.Style.BackColor property, not by row StyleTableCell.BackColor.
• When a cell is created, its Style inherits from the cell's own StyleTableCell. That is the only place where StyleTableCell actually affects how things look, by becoming the parent of the cell's Style. For objects inside the cell, the cell's own StyleTableCell becomes the default parent for all new styles instead of the root document style. Thus, if text is rendered inside a cell, its style will inherit from the cell's style, which in turn inherits from the cell's StyleTableCell. If a nested table is rendered inside a cell (a powerful feature also supported by C1PrintDocument), the cell's style becomes the "document root style" for the whole hierarchy of styles of the nested table.
The rules outlined above provide a powerful, flexible, and intuitive model for controlling tables. Let's look at a couple of examples.
Setting a Background Image
Suppose you want to have a background image beneath the whole table. Then you will write:
Table.Style.BackgroundImage = MyImage
• C#
Table.Style.BackgroundImage = MyImage;
The table as a whole will have a background image drawn beneath it, but that image will not be duplicated in any of the table elements.
Aligning Text in a Column
If you want to align text to the right in a specific column (say, column 3), you'll write:
Table.Columns(3).StyleTableCell.TextAlignHorz = C1.C1PrintDocument.AlignHorzEnum.Right
• C#
Table.Columns[3].StyleTableCell.TextAlignHorz = C1.C1PrintDocument.AlignHorzEnum.Right;
This will change text alignment in all cells in the column 3.
For a detailed discussion on how to control table borders, refer to section Gridlines in Tables.
Note: Similar rules are used when drawing render objects included in page headers and footers. The only difference is in the property name. Instead of StyleTableCell, StyleNested is used to draw elements inside page headers and footers. Thus, to draw a border around the whole page footer, footer.Style.Border should be used, while to draw a border around each render object inside the footer, footer.StyleNested.Border should be used.
|