我有3种打印方法:printa,printb和printc(每种打印一种形式)。所有3个表单都需要跨多个页面打印。如何在3页上打印?
我知道我们需要使用事件处理程序并使用currentpage和e.hasmorepages但我不确定如何使用它。
答案 0 :(得分:1)
只需跟踪页码即可。您在BeginPrint事件中将其设置为0,并在每次调用PrintPage时将其递增。像这样:
int pageNumber;
private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
pageNumber = 0;
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
++pageNumber;
e.HasMorePages = true;
switch (pageNumber) {
case 1: printa(e); break;
case 2: printb(e); break;
case 3: printc(e); e.HasMorePages = false; break;
}
}
答案 1 :(得分:0)
是的,它可能非常模糊。以下是我为printing Reporting Services报告(下面的代码中的MetaFile图像数组)所做的操作。
public void Print()
{
if (emfImage == null || emfImage.Count <= 0)
{
throw new ArgumentException("An image is required to print.");
}
printer = printer.Trim();
if (string.IsNullOrEmpty(printer))
{
throw new ArgumentException("A printer is required.");
}
printingPage = 0;
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = printer;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Metafile page = emfImage[printingPage];
e.Graphics.DrawImage(page, 0, 0, page.Width, page.Height);
e.HasMorePages = ++printingPage < emfImage.Count;
}