Creating Borders Around Rows and Columns in Your Table
Creating borders around rows and columns in your table demonstrates how to create distinct borders around a row and a column by using the LineDef class in C1PrintDocument. This topic assumes you already have a table with three columns and three rows.
1. The following code should already exist in your source file:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Make a table with 3 columns and 3 rows.
Dim table As C1.C1PrintDocument.RenderTable = New C1.C1PrintDocument.RenderTable(Me.C1PrintDocument1)
table.Columns.AddSome(3)
table.Body.Rows.AddSome(3)
' Generate the document.
Me.C1PrintDocument1.StartDoc()
Me.C1PrintDocument1.RenderBlock(table)
Me.C1PrintDocument1.EndDoc()
End Sub
• C#
private void Form1_Load(object sender, System.EventArgs e)
{
// Make a table with 3 columns and 3 rows.
C1.C1PrintDocument.RenderTable table = new C1.C1PrintDocument.RenderTable(this.c1PrintDocument1);
table.Columns.AddSome(3);
table.Body.Rows.AddSome(3);
// Generate the document.
this.c1PrintDocument1.StartDoc();
this.c1PrintDocument1.RenderBlock(table);
this.c1PrintDocument1.EndDoc();
}
2. Make the columns' width and rows' height six centimeters long by inserting the following code just before the StartDoc method:
table.Body.Rows(0).HeightStr = "6cm"
table.Columns(0).WidthStr = "6cm"
table.Columns(1).WidthStr = "6cm"
table.Body.Rows(1).HeightStr = "6cm"
table.Columns(2).WidthStr = "6cm"
table.Body.Rows(2).HeightStr = "6cm"
• C#
table.Body.Rows[0].HeightStr = "6cm";
table.Columns[0].WidthStr = "6cm";
table.Columns[1].WidthStr = "6cm";
table.Body.Rows[1].HeightStr = "6cm";
table.Columns[2].WidthStr = "6cm";
table.Body.Rows[2].HeightStr = "6cm";
3. Assign a new instance of the LineDef class to the borders of the third row as follows (note that the constructor we use specifies that the new border will be red and 2 points wide):
table.Body.Rows(2).Style.Borders.All = New C1.C1PrintDocument.LineDef(Color.Red, 2)
• C#
table.Body.Rows[2].Style.Borders.All = new C1.C1PrintDocument.LineDef(Color.Red, 2);
4. Assign a new instance of the LineDef class to the borders of the first column as follows (note that the constructor we use specifies that the new border will be orange and 6 points wide):
table.Columns(0).Style.Borders.All = New C1.C1PrintDocument.LineDef(Color.Orange, 6)
• C#
table.Columns[0].Style.Borders.All = new C1.C1PrintDocument.LineDef(Color.Orange, 6);
Run the program and observe the following:
Your borders will appear like this in your table at run time:
|