我可以使用下面的代码正确显示文本。但是,下面的代码有限制。它将在一页之后切断任何内容,并且不会显示任何格式。
如果我使用message.Rtf
代替message.Text
,则会吐出RTF代码,例如:
{\ RTF1 \ ansansicpg1252 \ deff0
如何使用格式和多个页面打印内容? Google上的每个链接都是紫色的,但无济于事。
private void printerHandler(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
StringReader reader = new StringReader(message.Text);
float LinesPerPage = 0;
float LeftMargin = e.MarginBounds.Left;
float TopMargin = e.MarginBounds.Top;
string Line = null;
Font PrintFont = this.message.Font;
SolidBrush PrintBrush = new SolidBrush(Color.Black);
LinesPerPage = e.MarginBounds.Height / PrintFont.GetHeight(e.Graphics);
RectangleF rect = new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Right - e.MarginBounds.Left, e.MarginBounds.Bottom - e.MarginBounds.Top);
Line = reader.ReadToEnd();
e.Graphics.DrawString(Line, PrintFont, PrintBrush, rect, new StringFormat());
e.HasMorePages = false;
PrintBrush.Dispose();
}