Adding a Background Color to the Page Header
This topic demonstrates how to add a background color to the page header, and uses the following objects:
• C1PrintDocument
• C1DocStyle
• RenderTable
Complete the following steps:
1. Create a new Windows Forms application.
2. Add a C1PrintPreview control onto your form.
3. Add a C1PrintDocument component onto your form – it will appear in the components' tray below the form. The preview will have the default name C1PrintPreview1, the document C1PrintDocument1.
4. Set the value of the Document property of C1PrintPreview1 control to C1PrintDocument1, so that the preview will show the document when the application runs.
5. Double click the form to create a handler for the Form_Load event – this is where you will add all the code shown below. Call the StartDoc method to start generating the document. We'll assign the table to the RenderTable class.
Me.C1PrintDocument1.StartDoc()
Dim theader As New C1.C1Preview.RenderTable(Me.C1PrintDocument1)
• C#
this.c1PrintDocument1.StartDoc();
C1.C1Preview.RenderTable theader = new C1.C1Preview.RenderTable(this.c1PrintDocument1);
6. In this example, we will assign a gold color to our page header in our table. We will use the Style property of the TableRow class to apply the background color to the table, theader.
theader.Style.BackColor = Color.Gold
• C#
theader.Style.BackColor = Color.Gold;
7. We'll need to create a table with one row and one column. We will draw some text onto our table for our page header. We will make our text right-aligned. We create a new font type of Arial and font size of 14 points, for our text.
theader.Cells(0, 0).Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Right
' Set up some styles.
theader.CellStyle.Font = New Font("Arial", 14)
' Assign text.
theader.Cells(0, 0).Text = "Swim Team Practice Schedule"
' Set the table as the page header.
Me.C1PrintDocument1.RenderBlock(theader)
Me.C1PrintDocument1.EndDoc()
• C#
theader.Cells[0, 0].Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Right;
// Set up some styles.
theader.CellStyle.Font = new Font("Arial", 14);
// Assign text.
theader.Cells[0, 0].Text = "Swim Team Practice Schedule";
// Set the table as the page header.
this.c1PrintDocument1.RenderBlock(theader);
this.c1PrintDocument1.EndDoc();
Run the program and observe the following:
Your header should look similar to the following header:
|