0
我想打印數據網格中的數據。該代碼適用於第一頁,但註釋行不能正常工作,不會移動到下一頁。誰能幫助解決這個問題嗎?PrintDocument HasMorePages不工作
private void DrawFactorA4(object sender, PrintPageEventArgs ev)
{
for (int j = 0; j < GrdRDocument.Rows.Count; j++)
{
i += 2;
//draw data grid
s++;
if(s == 10)
{
//ev.HasMorePages = true; //this line doesn't work
s = 0;
i = 0;
}
else
{
ev.HasMorePages = false;
}
}
}
_
private void BtnPrint_Click(object sender, EventArgs e)
{
printFont = new Font("Arial", 12);
IEnumerable<PaperSize> paperSizes =
pd.PrinterSettings.PaperSizes.Cast<PaperSize>();
sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4);
pd.DefaultPageSettings.Landscape = true;
pd.DefaultPageSettings.PaperSize = sizeA4;
pd.PrintPage += new PrintPageEventHandler(this.DrawFactorA4);
printPreviewDialog.Document = pd;
printPreviewDialog.ShowDialog();
}
它工作正常,它只是使用錯誤太頻繁。就像它在這裏一樣,你必須離開for()循環。當你的事件處理程序再次被調用時,在下一行繼續,這需要'j'成爲你的類的一個字段。並且需要實施BeginPrint,因此您可以將其設置爲0。 –