2015-08-25 37 views
0

這就是我的PrintPage事件處理程序代碼全頁不打印

private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
{ 
    int yaxis = 0; 
    Font font = new Font("Arial", 12, FontStyle.Bold); 
    for (int i = 0; i < 300; i++) 
    { 
     e.Graphics.DrawString("Store Inventory Report", font, Brushes.Black, 0, yaxis); 
     yaxis += 30; 
    } 
} 

此代碼僅打印行37倍。 。 。它沒有打印整頁。 。我生成pdf,pdf也有37行。

enter image description here

+0

你指定頁面大小? – Jcl

+0

您是否檢查發送到實際打印機時的打印區域?可打印邊距可能與pdf版本不同。嘗試更改'Font'大小或'yaxis'來查看您是否在可打印區域外進行打印。 –

+0

@JCL不,我沒有指定大小。 。 .i希望所有300行可以在1頁上打印,因此我可以在熱敏打印機上打印 –

回答

0

隨着完整的打印您的意思是打印在你的代碼的所有300線基地?如果是你應該設置參數:

e.HasMorePages = true; 

當你達到所有內容已被打印的條件時,將它設置爲false。

對於你的情況會是這樣的:

private int startIndex = 0; //Keeps track of printed index 
private int limit = 300; //Limit of items to print 

private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
{ 
    int yaxis = 0; 
    Font font = new Font("Arial", 12, FontStyle.Bold); 
    for (int i = startIndex; i < limit; i++) 
    { 
     e.Graphics.DrawString("Store Inventory Report", font, Brushes.Black, 0, yaxis); 
     yaxis += 30; 

     //Reaches bottom? break the loop 
     if (yaxis > e.PageBounds.Bottom) 
     { 
      startIndex = i + 1; //Set to next page's data index 
      break; 
     } 
    } 

    //Still has pages? 
    e.HasMorePages = startIndex < limit; 

} 
+0

仍然是同樣的問題。 。 。我只想要在一個頁面上的所有300行。 。 .so我可以在打印機上打印它 –

+0

所以,你的意思是在一頁上打印300行?那麼你必須限制你的案例中的字體大小和垂直間距,以適應300個項目。 –