【发布时间】:2013-01-10 16:51:20
【问题描述】:
我正在关注 MSDN 关于打印多页的“操作方法”文档:How to: Print a Multi-Page Text File in Windows Forms
我已经将该页面上的示例变成了一个项目(尝试了 Visual Studio 2010 和 2012),发现它在打印少量页面时按预期工作,但在打印大量页面时(大约 9 页)它开始将开始页面呈现为空白(第一页和第二页是空白的,接下来的 15 页是正确的,等等)。
谁能确认这种行为?我看不出是什么原因造成的,也没有抛出异常。
这是我认为包含问题的代码部分:
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
int charactersOnPage = 0;
int linesPerPage = 0;
// Sets the value of charactersOnPage to the number of characters
// of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(stringToPrint, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
// Draws the string within the bounds of the page
e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
// Remove the portion of the string that has been printed.
stringToPrint = stringToPrint.Substring(charactersOnPage);
// Check to see if more pages are to be printed.
e.HasMorePages = (stringToPrint.Length > 0);
}
我认为没有任何数据类型被溢出。我用不同的打印机试过这个,但每一个都有相同的结果。
注意:我尝试过 .NET Framework 4 和 4.5,结果相同。
【问题讨论】:
-
注意:我已经在多台计算机和操作系统上尝试过,结果相同。
标签: c# .net winforms visual-studio printing