将VS Community 2017与.NET Framework 4.6一起使用。
以下代码摘自MS文档,适用于打印到打印机,但在PrintPreviewDialog调用中有限制。
string text;
string ToPrint;
private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.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(ToPrint, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
// Draws the string within the bounds of the page.
e.Graphics.DrawString(ToPrint, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
// Remove the portion of the string that has been printed.
ToPrint = ToPrint.Substring(charactersOnPage);
// Check to see if more pages are to be printed.
e.HasMorePages = (ToPrint.Length > 0);
// If there are no more pages, reset the string to be printed.
if (!e.HasMorePages)
ToPrint = text;
}
经过试验,我发现如果“ ToPrint”字符串的长度大于32490个字符,则e.Graphics.DrawString会生成空白的打印预览页。
有人知道这是为什么吗?我缺少某些设置或选项吗?
谢谢