这是我的代码,当我打印一页时工作正常,但是当我尝试打印不适合一页的内容时,它不会开始新页面,它只是接受偏移量更改并开始在第一页上书写.
有谁知道该怎么做?
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphic = e.Graphics;
Font font = new Font("Courier New", 12);
float fontHeight = font.GetHeight();
int startX = 10;
int startY = 10;
int offset = 0;
float pageWidth = e.PageSettings.PrintableArea.Width;
float pageHeight = e.PageSettings.PrintableArea.Height;
foreach (string line in textRichTextBox.Lines)
{
graphic.DrawString(line, font, new SolidBrush(Color.Black), startX, startY + offset);
offset += (int)fontHeight;// + 5
if (offset >= pageHeight - (int)fontHeight)
{
e.HasMorePages = true;
offset = 0;
}
}
e.HasMorePages = false;
}