如何使用打印文档打印标题页



我有一个打印文档,我想用它打印第一页——标题或封面。然后,下一页的其他内容。

我能够成功地创建printDocument控件,并将其printpage事件与我的方法链接起来。

它打印。然而,我实际上想打印出我的打印封面。我一直盯着我的代码看,但无法想出一个适合所有人的解决方案。

我要么有一个单独的printDocument只用于标题页,另一个printDocument用于其他所有内容,并有自己的printPage事件,要么在标题页和其他所有内容的printPage事件中有if-else块。

那么,你会怎么做呢?举个例子将不胜感激。

谢谢,

在我的脑海中:

// 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...
}

最新更新