How to print a RichTextBox in Visual Basic 6 using BSPrinter
The VB6 Rich TextBox control can be printed with BSPrinter with one line of code:
PrintPreview1.PrintRichTextBox RichTextBox1
Where 'PrintPreview1' is the name of the PrintPreview control and 'RichTextBox1' is the name of the RTB control.
To test it, add a PrintPreview control to a form (you need BSPrinter component installed, if you don't have it download it from the download page), a RichTextBox control, a Command button and this code:
Private Sub Command1_Click()
' show the Print Preview dialog
PrintPreview1.ShowPreview
End Sub
Private Sub PrintPreview1_PrepareReport(Cancel As Boolean)
' the following is the only line needed to print the RichTextBox control
PrintPreview1.PrintRichTextBox RichTextBox1
End Sub
Private Sub Form_Load()
RichTextBox1.LoadFile ([RTB file path])
End Sub
You also will need to add this code in a module (or in the form). This is to replace the VB6 original printer object with a new one:
Public Property Get Printer() As Printer
Set Printer = PrinterReplacement
End Property
Public Property Set Printer(nPrinter As Printer)
Set PrinterReplacement = nPrinter
End Property
In the sample projects that are installed by the installer at [Program Files]\BSPrinter\Samples or [Program Files (x86)]\BSPrinter\Samples on Windows 64 bits, there is a sample project for printing the RTB, it is sample 4:
4 - Print RichTextBox
Reference
PrintRichTextBox method.