Examples in this group show how to draw tables on a GrapeCity.Documents.Drawing.GcGraphics
(such as GcBitmapGraphics, GcSvgGraphics, etc.) with the GrapeCity.Documents.Drawing.TableRenderer class.
TableRenderer can be used together with classes from the GrapeCity.Documents.Layout.Composition namespace
to draw complex layouts including tables, text and graphics.
TableRenderer (GrapeCity.Documents.Drawing.TableRenderer)
Represents a helper class for drawing tables with merged, rotated, auto-sized, multilayer cells and customizable cell styles.
Table cells can contain simple text, multi-formatted TextLayout, or owner-drawn content.
The TableRenderer class is built on top of the layout engine (see GrapeCity.Documents.Layout.LayoutHost and related classes).
FrameStyle (GrapeCity.Documents.Drawing.FrameStyle)
Represents the border and fill style for table frames or table cells. Its properties specify
line padding, line width, line color, content filling, and corner radius.
CellStyle (GrapeCity.Documents.Drawing.CellStyle, derived from FrameStyle)
Adds settings for table cells' z-order, inner border, content fill and text layout. There are
properties specifying text format, rotation, alignment, and allowed text width.
The CustomDraw delegate allows you to draw custom content (e.g. a nested table) inside a table cell.
One CellStyle can be associated with multiple table cells.
TableCell (GrapeCity.Documents.Drawing.TableCell)
Represents the style and content (data) associated with a specific cell in a table.
TableCell contains information about the cell's row and column indices, the number of merged rows and columns,
the width and height of the cell in graphic units.
Drawing a table typically involves the following steps:
Create a rectangle (LayoutRect) for the table. There are two possible approaches.
You can either use helper classes from the GrapeCity.Documents.Layout.Composition namespace,
or classes from the GrapeCity.Documents.Layout namespace directly:
If using helper composition classes: create a Surface object, then create a View (e.g. with the size of the target page).
Use the View object to create a Visual that will host the table. The Visual object has the associated LayoutRect object.
Or, if using layout classes directly, create a LayoutHost object, then create a LayoutView
with the target page's width and height. Use the LayoutView object to create a LayoutRect.
Set constraints for the table LayoutRect. You must fix at least one corner of the table.
The position of other corners will then be calculated depending on the table content.
You can also fix two corners of the table (e.g. by setting constraints for its top, left, and right sides), or all four.
The value of the fixedSides parameter passed to the TableRenderer constructor must be chosen accordingly.
Create a TableRenderer object, passing GcGraphics, LayoutRect, and other parameters to the constructor. The number
of table rows and columns, as well as table padding settings, are passed to the constructor and cannot be changed later.
If necessary, apply additional constraints to some column widths and row heights. The default minimum column width
and minimum row height can be passed to the TableRenderer constructor.
As needed, create CellStyle objects with text formats, padding settings, and other adjustments. Usually it is convenient to create
a base cell style, then create other more specific styles based on it.
Use the TableRenderer.AddCell() method to add table cells with the prepared cell styles and table data. Some cells
can span multiple columns and rows. Cells using background or foreground styles might overlap multiple regular cells,
for example, to display highlighted rows.
If needed, call the TableRenderer.AddMissingCells() method to add empty cells to fill out any gaps in the table.
Grid lines will not be drawn around empty cells otherwise.
When all constraints are specified and all cells added, if you're working with the LayoutHost object directly,
just call the TableRenderer.Render() method. It draws the table on the GcGraphics object passed to the constructor.
Or, if you created the Surface and Visual objects, a few additional steps must be performed:
Call the TableRenderer.ApplyCellConstraints() method to calculate the table layout.
Attach the Draw delegate to the Visual object. In its code you need to assign GcGraphics.Transform to
Visual.Layer.Surface.BaseTransform and then execute the TableRenderer.Render() method.
Now you can draw the Surface with one or more tables and other visuals. Call the Surface.Render() method,
passing the target GcGraphics object to it.