Search code examples
.netvb.netprintingheaderprintdocument

Easiest way to add a Header and Footer to a Printing.PrintDocument (.Net 2.0)?


What's the easiest way to add a header and footer to a .Net PrintDocument object, either pragmatically or at design-time?

Specifically I'm trying to print a 3rd party grid control (Infragistics GridEx v4.3), which takes a PrintDocument object and draws itself into it.

The resulting page just contains the grid and it's contents - however I would like to add a header or title to identify the printed report, and possibly a footer to show who printed it, when, and ideally a page number and total pages.

I'm using VB.Net 2.0.

Thanks for your help!


Solution

  • The printdocument object fires the printpage event for each page to be printed. You can draw text/lines/etc into the print queue using the printpageeventargs event parameter:

    http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

    Dim it WithEvents when you pass it to the grid, so you can handle the event.