The VBCompanion provides excellent helpers that provide a lot fo the VB6 Printer object functionality, so you dont have to change any of your actual code, but in some cases, you might just want to remove that code, specially for very specific things like printing a RichTextBox.

So here I’m providing a .NET simplified helper that allows you to print the contents of a RichTextBox control. This helper is just based on the code published by Martin Muller in http://msdn.microsoft.com/en-us/library/ms996492.aspx. It provides an extension method for VS 2008 user so all you have to do is call RichTextBox.Print.

The implementation is simple. The RichTextBoxPrintHelper creates or receives an instance of a PrintDocument object, and event handlers are added to it for the BeginPrint, PrintPage and EndPrint events.

privateint m_nFirstCharOnPage;
privatevoid printDocument_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
// Start at the beginning of the text
m_nFirstCharOnPage = 0;
}
privatevoid printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
// To print the boundaries of the current page margins// uncomment the next line://e.Graphics.DrawRectangle(System.Drawing.Pens.Blue, e.MarginBounds);// make the RichTextBoxEx calculate and render as much text as will// fit on the page and remember the last character printed for the// beginning of the next page
m_nFirstCharOnPage = FormatRange(false,
e,
m_nFirstCharOnPage,
control.TextLength);
// check if there are more pages to printif (m_nFirstCharOnPage < control.TextLength)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
privatevoid printDocument_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
// Clean up cached information
FormatRangeDone();
}

The FormatRange method is called. This method will use the fill out some structures with page information and use the RichTextBox handle to send messages that will renderthe control contents to the Printer’s HDC.

IE7 has an interesting bug...
Someone decided to change the printing default
to "Shrink to Fit".This is supposed to be good
because it will make printing of web pages better
but it affects several applications develop for
IE, for example if you are using the Web Access
to your Exchange server, or if you have an application
that prints on a page that is not a letter size page