ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Getting Started with Printing and Previewing > C1PrintDocument Quick Start > Creating Page Headers in C1PrintDocument > Creating a Page-Header with Three Parts

Creating a Page-Header with Three Parts

This topic demonstrates how to create a header that is divided into three columns. The following key points are shown in this topic:

      Creating a table with one row and three columns in C1PrintDocument.

      Setting up the text alignment in each section of the page header.

      The TextAlignHorz property of the Style class is used to specify the horizontal alignment of the text. You can assign a member (left, right, justify or center) of the AlignHorzEnum to the TextAlignHorz property.

The following detailed steps demonstrate how to create a header with three parts.

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 the 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 all code shown below will be written. In the Form_Load event, we will set up our document. Create a RenderTable for the page header:

      Visual Basic

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.   Add one row to its body, and 3 columns for the left, middle, and right parts of the header. We will use the TextAlignHorz property to set the alignment of the text in each column of the page header. We will also assign a new font style for the text in our page header. Note, in this example the font type will be Arial and it will be 14 points in size.

      Visual Basic

' Set up alignment for the parts of the header.

theader.Cells(0, 0).Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Left

theader.Cells(0, 1).Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Center

theader.Cells(0, 2).Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Right

theader.CellStyle.Font = New Font("Arial", 14)

      C#

// Set up alignment for the columns of the header.

theader.Cells[0, 0].Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Left;

theader.Cells[0, 1].Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Center;

theader.Cells[0, 2].Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Right;

theader.CellStyle.Font = new Font("Arial", 14);

7.   We will draw the text into each column of the table for the page header. Set the RenderObject property of the document's PageHeader to theader. Finish generating the document by calling the EndDoc method.

      Visual Basic

theader.Cells(0, 0).Text = "Left part"

theader.Cells(0, 1).Text = "Center part"

theader.Cells(0, 2).Text = "Right part"

Me.C1PrintDocument1.RenderBlock(theader)

Me.C1PrintDocument1.EndDoc()

      C#

theader.Cells[0, 0].Text = "Left part";

theader.Cells[0, 1].Text = "Center part";

theader.Cells[0, 2].Text = "Right part";

this.c1PrintDocument1.RenderBlock(theader);

this.c1PrintDocument1.EndDoc();

Run the program and observe the following:

Your new page header with three parts will appear similar to the header below at run time:

 


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.