ComponentOne Preview Classic for WinForms: Preview Classic for WinForms Task-Based Help > Displaying an Image in the Header of C1PrintDocument

Displaying an Image in the Header of C1PrintDocument

To display an image in the header of C1PrintDocument, create a table with a background image and render the table to the page header section at run time.

This example assumes that you have already created a table. For details on how to create a table, see Creating Tables in C1PrintDocument. In this example the RenderTable is called tblheader and consists of two columns and one row.

1.   Hide the table borders by adding the following code to the Form_Load event:

      Visual Basic

' Hide the table borders.

tblheader.Style.Borders.AllEmpty = True

tblheader.StyleTableCell.BorderTableVert.Empty = True

      C#

// Hide the table borders.

tblheader.Style.Borders.AllEmpty = true;

tblheader.StyleTableCell.BorderTableVert.Empty = true;

2.   Set the width and height of the table to fit the image:

      Visual Basic

' Set the width and height of the table.

tblheader.Columns(0).WidthStr = "50%"

tblheader.Columns(1).WidthStr = "50%"

tblheader.Body.Rows(0).HeightStr = "15mm"

      C#

// Set the width and height of the table.

tblheader.Columns[0].WidthStr = "50%";

tblheader.Columns[1].WidthStr = "50%";

tblheader.Body.Rows[0].HeightStr = "15mm";

3.   Set the KeepAspectRatio property to True to maintain the shape of the image and the AlignHorz property to Right:

      Visual Basic

' Set the image appearance and alignment.

tblheader.Body.Cell(0, 1).StyleTableCell.BackgroundImageAlign.KeepAspectRatio = True

tblheader.Body.Cell(0, 1).StyleTableCell.BackgroundImageAlign.AlignHorz = C1.C1PrintDocument.ImageAlignHorzEnum.Right

      C#

// Set the image appearance and alignment.

tblheader.Body.Cell(0, 1).StyleTableCell.BackgroundImageAlign.KeepAspectRatio = true;

tblheader.Body.Cell(0, 1).StyleTableCell.BackgroundImageAlign.AlignHorz = C1.C1PrintDocument.ImageAlignHorzEnum.Right;

4.   Set the background image and render it to the page header section.

      Visual Basic

' Set the background image in the table.

Dim image As System.Drawing.Image

image = System.Drawing.Image.FromFile("c:\c1logo.bmp")

tblheader.Body.Cell(0, 1).StyleTableCell.BackgroundImage = image

 

Me.C1PrintDocument1.StartDoc()

 

' Render the table to the page header section.

Me.C1PrintDocument1.PageHeader.RenderObject = tblheader

Me.C1PrintDocument1.EndDoc()

      C#

// Set the background image in the table.

System.Drawing.Image image;

image = System.Drawing.Image.FromFile(@"c:\c1logo.bmp");

tblheader.Body.Cell(0, 1).StyleTableCell.BackgroundImage = image;

 

this.c1PrintDocument1.StartDoc();

 

// Render the table to the page header section.

this.c1PrintDocument1.PageHeader.RenderObject = tblheader;

this.c1PrintDocument1.EndDoc();

This topic illustrates the following:

Your C1PrintDocument should appear similar to the one below, with the image appearing in the second cell of the header table.

 


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