I can get the text to come out correctly with the code below. The code below has restrictions, however. It will cut off anything after one page, and won't show any formatting.

If I use message.Rtf instead of message.Text, it spits out RTF codes like:

{\rtf1\ansansicpg1252\deff0

How can I get things to print with formatting, and more than one page? Every link on Google is purple, to no avail.

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();
}
有帮助吗?

解决方案

This should work for you

RTF Printer Control

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top