2011-07-21 185 views
0

我有3種打印方法:printa,printb和printc(每種打印表格)。所有3種形式都需要在多個頁面上打印。我怎樣才能打印3頁?在多個頁面上打印表格

我知道我們需要使用事件處理程序並使用currentpage和e.hasmorepages,但我不確定如何使用它。

回答

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; 
     } 
    } 
+0

This works.thank you – laila

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; 
}