| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic .NET |
| Version: | 1.0 |
| Released: | July 29, 2005 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control .NET with Visual Basic .NET |
| Download code: | tx_net_sample_preview.zip |

In this sample we would like to show you another .NET component that works well with the TX Text Control .NET. The ComponentOne Preview .NET component offers some advantages over the standard VS .NET print preview.
ComponentOne's control comes with the C1PrintPreview component and the C1PrintDocument component. In this sample, we are going to use the preview component only.
Using the components together is quite straight-forward: You need to create a custom PrintController, so that TX Text Control does not send its contents to the standard printer. The dummy PrintController does not do anything except return a Graphics object in the OnStartPage handler. As you cannot create a Graphics object without a Form or a Screen object, a reference to the parent form has to be set with the SetParent method.
Private Class MyPrintController Inherits System.Drawing.Printing.PrintController Private parent As Form1 Public Sub New() MyBase.New() End Sub Public Sub SetParent(ByVal form As Form1) parent = form End Sub Public Overloads Overrides Function OnStartPage(ByVal document_ As System.Drawing.Printing.PrintDocument, ByVal e As System._ Drawing.Printing.PrintPageEventArgs) As System.Drawing.Graphics OnStartPage = parent.CreateGraphics() End Function Public Overloads Overrides Sub OnEndPage(ByVal document As_ System.Drawing.Printing.PrintDocument, ByVal e As System.Drawing._ Printing.PrintPageEventArgs) End Sub Public Overloads Overrides Sub OnEndPrint(ByVal document As_ System.Drawing.Printing.PrintDocument, ByVal e As System.Drawing._ Printing.PrintEventArgs) End Sub Public Overloads Overrides Sub OnStartPrint(ByVal document As_ System.Drawing.Printing.PrintDocument, ByVal e As System.Drawing._ Printing.PrintEventArgs) End Sub
The CreateGraphics method of this reference can be used in the OnStartPage event handler. Have a look at the code to see how it works.
Note that at least TX Text Control .NET 10.1 trial, a trial version of ComponentOne Preview .NET and Visual Studio VB .NET are required to run this sample.