我在打印 listView 项目时遇到问题。我认为问题出在private void PrintPageDetail(PrintPageEventArgs e)
所以这就是发生的事情:
它一遍又一遍地打印适合一页的任何内容。(有比打印的更多的数据)虽然页脚和页眉打印正确的页码。而且我很难让它每次都清除内存以在下一页上映射新数据。
打印预览和打印不会停止,除非我点击取消(可能是由于无限循环“return;”)。
感谢您的任何帮助
private void PrintDocument(object sender, PrintPageEventArgs e)
{
// Use inches for all measurements.
e.Graphics.PageUnit = GraphicsUnit.Inch;
PrintPageHeader(e);
PrintPageDetail(e);
PrintPageFooter(e);
}
// Print the page header/footer/details.
private void PrintPageHeader(PrintPageEventArgs e)
{
e.Graphics.DrawString("Factors List Report",
_headerFont, _reportBrush, 3.0F, 0.75F);
e.Graphics.DrawLine(_reportPen, 0.5F, 1.15F, 7.5F, 1.15F);
}
private void PrintPageFooter(PrintPageEventArgs e)
{
e.Graphics.DrawLine(_reportPen, 1.0F, 10.0F, 7.5F, 10.0F);
e.Graphics.DrawString("Printed on " + DateTime.Now.ToLongDateString(),
_footerFont, _reportBrush, 1F, 10.2F);
_pageNumber++;
e.Graphics.DrawString(string.Format("Page: {0}", _pageNumber),
_footerFont, _reportBrush, 7F, 10.2F);
}
private void PrintPageDetail(PrintPageEventArgs e)
{
// Create variables to hold position on page.
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float i = 1.25F;
e.HasMorePages = false;
foreach (string printerLine in _factorsView)
{
e.Graphics.DrawString(printerLine, _detailFont, _reportBrush, 1.0F, i);
if (i >= 9.75)
{
i += 1.25F;
e.HasMorePages = true;
return;
}
else
i += .25F;
}
}
}