Reputation: 3276
I have a printdocument and with it I want to print first page - title or cover page. Then, everything else on the next page.
I am able to successfully create the printDocument control and link its printpage event with my method.
It prints. However, I actually want to print cover page for my print out. I keep staring at my code but can't come up with one solution that fits all.
I either have to have a separate printDocument just for title page and another printDocument for everything else with their own printPage event or have if else block within printpage event for title page and everthing else.
So, how would you do it? An example would be greatly appreciated.
Thanks,
Upvotes: 1
Views: 2321
Reputation: 35869
Off the top of my head:
// set to false before calling PrintDocument.Print()
bool firstPagePrinted = false;
private void printdocument_PrintPage(object sender, PringPageEventArgs e)
{
if(!firstPagePrinted)
{
// TODO: whatever you want
e.Graphics.DrawString("Header page", printFont,
Brushes.Black, e.MarginBounds.left, e.MarginBounds.Top, new StringFormat();
firstPagePrinted = true;
e.HasMorePage = true;
}
// do 2nd and subsequent pages here...
}
Upvotes: 2