複数ページの印刷に関する MSDN の「ハウツー」ドキュメントに従っています:方法: Windows フォームで複数ページのテキスト ファイルを印刷する
そのページの例をプロジェクトに変えました (Visual Studio 2010 および 2012 を試しました)。少量のページを印刷する場合は期待どおりに動作することがわかりましたが、大量 (9 ページ程度) を印刷するとレンダリングが開始されます。最初のページは空白 (1 ページ目と 2 ページ目は空白、次の 15 ページは正しいなど)。
誰でもこの動作を確認できますか? 何がこれを引き起こしているのかわかりません。例外はスローされません。
編集: 2 つの反対票を受け取りましたが、理由がわかりません。もっと明確にしようと思います。問題が含まれていると思われるコードのセクションは次のとおりです。
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 を試しましたが、同じ結果が得られました。