[]
A helper class for drawing tables on a GcGraphics.
This class is based on the layout engine (see LayoutHost and related classes), and supports drawing simple or complex tables with merged, rotated, auto-sized, multilayer cells with customizable styles. Table cells can contain simple text, multi-formatted TextLayout, or owner-drawn content.
public class TableRenderer
Initializes a new instance of the TableRenderer class.
public TableRenderer(GcGraphics graphics, LayoutRect tableRect, FixedTableSides fixedSides, int rowCount, int columnCount, Color gridLineColor, float gridLineWidth, float? rowMinHeight = null, float? columnMinWidth = null, float? paddingAll = null, float paddingLeft = 0, float paddingTop = 0, float paddingRight = 0, float paddingBottom = 0)
graphics
GcGraphicsA GcGraphics used for creating TextLayout objects.
tableRect
LayoutRectA LayoutRect of the table.
fixedSides
FixedTableSidesSpecifies which sides of a table are fixed, i.e. don't move depending on the table content.
rowCount
intThe overall number of rows in the table.
columnCount
intThe overall number of columns in the table.
gridLineColor
System.Drawing.ColorThe color of grid lines.
gridLineWidth
floatThe default grid line width, in graphic units.
rowMinHeight
float?The optional minimal height for each row, in graphic units.
columnMinWidth
float?The optional minimal width for each column, in graphic units.
paddingAll
float?All sides padding relative to the table rectangle, in graphic units.
paddingLeft
floatLeft side padding relative to the table rectangle, in graphic units.
paddingTop
floatTop side padding relative to the table rectangle, in graphic units.
paddingRight
floatRight side padding relative to the table rectangle, in graphic units.
paddingBottom
floatBottom side padding relative to the table rectangle, in graphic units.
Gets a read-only list of all table cells.
public IReadOnlyList<TableCell> Cells { get; }
Gets the number of columns in the table.
public int ColumnCount { get; }
Gets the array of column LayoutRects.
public LayoutRect[] ColumnRects { get; }
Gets or sets the default CellStyle.
public CellStyle DefaultCellStyle { get; set; }
Gets a GcGraphics used for creating TextLayout objects.
public GcGraphics Graphics { get; }
Gets or sets the color of grid lines.
public Color GridLineColor { get; set; }
Gets the array of LayoutRects for horizontal grid lines.
public LayoutRect[] HorizontalGridLineRects { get; }
Gets a regular table cell at the specified rowIndex
and columnIndex
.
Background and foreground cells can be obtained with the Cells property.
public TableCell this[int rowIndex, int columnIndex] { get; }
rowIndex
intcolumnIndex
intGets the number of rows in the table.
public int RowCount { get; }
Gets the array of row LayoutRects.
public LayoutRect[] RowRects { get; }
Gets or sets the style of the outer table frame.
public FrameStyle TableFrameStyle { get; set; }
Gets a LayoutRect for the table.
public LayoutRect TableRect { get; }
Gets the array of LayoutRects for vertical grid lines.
public LayoutRect[] VerticalGridLineRects { get; }
Creates a table cell with given style and a new TextLayout inside.
public TableCell AddCell(CellStyle cellStyle, int rowIndex, int columnIndex, int rowSpan, int columnSpan, object data)
cellStyle
CellStyleThe style of the cell, or null to use the default style.
rowIndex
intIndex of top row in the cell.
columnIndex
intIndex of left column in the cell.
rowSpan
intThe number of rows covered by a cell.
columnSpan
intThe number of columns covered by a cell.
data
objectA data object or string to be displayed in the cell.
Creates an empty table cell with given style at the specified position.
public TableCell AddCell(CellStyle cellStyle, int rowIndex, int columnIndex, int rowSpan = 1, int columnSpan = 1)
cellStyle
CellStyleThe style of the cell, or null to use the default style.
rowIndex
intIndex of top row in the cell.
columnIndex
intIndex of left column in the cell.
rowSpan
intThe number of rows covered by a cell.
columnSpan
intThe number of columns covered by a cell.
Creates a table cell with given style and a new TextLayout inside.
public TableCell AddCell(CellStyle cellStyle, int rowIndex, int columnIndex, object data)
cellStyle
CellStyleThe style of the cell, or null to use the default style.
rowIndex
intIndex of top row in the cell.
columnIndex
intIndex of left column in the cell.
data
objectA data object or string to be displayed in the cell.
Creates a table cell with default style and a new TextLayout inside.
public TableCell AddCell(int rowIndex, int columnIndex, int rowSpan, int columnSpan, object data)
rowIndex
intIndex of top row in the cell.
columnIndex
intIndex of left column in the cell.
rowSpan
intThe number of rows covered by a cell.
columnSpan
intThe number of columns covered by a cell.
data
objectA data object or string to be displayed in the cell.
Creates an empty table cell with default style at the specified position.
public TableCell AddCell(int rowIndex, int columnIndex, int rowSpan = 1, int columnSpan = 1)
rowIndex
intIndex of top row in the cell.
columnIndex
intIndex of left column in the cell.
rowSpan
intThe number of rows covered by a cell.
columnSpan
intThe number of columns covered by a cell.
Creates a table cell with default style and a new TextLayout inside.
public TableCell AddCell(int rowIndex, int columnIndex, object data)
rowIndex
intIndex of top row in the cell.
columnIndex
intIndex of left column in the cell.
data
objectA data object or string to be displayed in the cell.
Adds the regular cells to fill out the gaps in the specified rectangular range of table cells.
public void AddMissingCells(CellStyle cellStyle, int rowIndex, int columnIndex, int rowCount, int columnCount, object data)
cellStyle
CellStyleThe style of the new cells, or null to apply the default cell style.
rowIndex
intIndex of top row in the cell range.
columnIndex
intIndex of left column in the cell range.
rowCount
intNumber of rows in the cell range.
columnCount
intNumber of columns in the cell range.
data
objectA data object or string to be displayed in the cells.
Adds empty regular cells to fill out the gaps in the specified rectangular range of table cells.
public void AddMissingCells(CellStyle cellStyle, int rowIndex, int columnIndex, int rowCount, int columnCount)
cellStyle
CellStyleThe style of the new cells, or null to apply the default cell style.
rowIndex
intIndex of top row in the cell range.
columnIndex
intIndex of left column in the cell range.
rowCount
intNumber of rows in the cell range.
columnCount
intNumber of columns in the cell range.
Adds the regular cells to fill out the gaps in the table.
public void AddMissingCells(CellStyle cellStyle, object data)
cellStyle
CellStyleThe style of the new cells, or null to apply the default cell style.
data
objectA data object or string to be displayed in the cells.
Adds empty regular cells to fill out the gaps in the table.
public void AddMissingCells(CellStyle cellStyle = null)
cellStyle
CellStyleThe style of the new cells, or null to apply the default cell style.
Adds the regular cells to fill out the gaps in the specified rectangular range of table cells.
public void AddMissingCells(int rowIndex, int columnIndex, int rowCount, int columnCount, object data)
rowIndex
intIndex of top row in the cell range.
columnIndex
intIndex of left column in the cell range.
rowCount
intNumber of rows in the cell range.
columnCount
intNumber of columns in the cell range.
data
objectA data object or string to be displayed in the cells.
Adds empty regular cells to fill out the gaps in the specified rectangular range of table cells.
public void AddMissingCells(int rowIndex, int columnIndex, int rowCount, int columnCount)
rowIndex
intIndex of top row in the cell range.
columnIndex
intIndex of left column in the cell range.
rowCount
intNumber of rows in the cell range.
columnCount
intNumber of columns in the cell range.
Performs layout of the table cells.
Execute this method after adding all cells to the table.
public void ApplyCellConstraints()
Draws the table to a GcGraphics.
public void Render(GcGraphics graphics = null)
graphics
GcGraphicsThe target GcGraphics. If null, the value is taken from the Graphics property.
The resolution of graphics
must be the same as of Graphics.
Sets the width of horizontal grid line with a specified index.
public void SetHorizontalGridLineWidth(int horizontalGridLineIndex, float gridLineWidth)
horizontalGridLineIndex
intIndex of the horizontal grid line [0..RowCount].
gridLineWidth
floatThe height of the horizontal grid line, in graphic units.
Sets the width of vertical grid line with a specified index.
public void SetVerticalGridLineWidth(int verticalGridLineIndex, float gridLineWidth)
verticalGridLineIndex
intIndex of the vertical grid line [0..ColumnCount].
gridLineWidth
floatThe width of the vertical grid line, in graphic units.