TX Text Control Source Code Library

Printing into a PrintPreview control

TX Text Control implements the standard print preview dialog of the .NET Framework. Using the PrintPreview method, a PrintDocument can be passed to open this dialog. However, it is not possible to manipulate the dialog using this approach. Sometimes, it is necessary to maximize the form on showing the dialog.

Using TX Text Control's Print method, it is possible to print into a PrintDocument. This PrintDocument can be passed to a standard print preview dialog.

 

 

private void button1_Click(object sender, EventArgs e) { PrintDocument pd = new PrintDocument(); PrintPreview(pd); }

In TX Text Control 14, sections have been introduced as a new feature, so a single document may hold different page formats and orientations. The OnPrintPage and OnQueryPageSettings events are used in this case to handle the number of pages to be printed and the current page's settings.

private void OnPrintPage(object obj, PrintPageEventArgs ppe) { // print the contents of TX Text Control textControl1.Print(m_currentPage, ppe); if (m_currentPage == textControl1.Pages) ppe.HasMorePages = false; else { ppe.HasMorePages = true; m_currentPage++; } } private void OnQueryPageSettings(object obj, QueryPageSettingsEventArgs qpe) { // retrieve the page orientation of the currently printed page textControl1.InputPosition = new TXTextControl.InputPosition(m_currentPage, 1, 0); qpe.PageSettings.Landscape = textControl1.Sections.GetItem().Format.Landscape; }

A good sample for the use of sections is to append several documents and to print the result. This can be easily tested with this sample, just perform the following steps:

  1. Insert some text.
  2. Insert a new section at the end of the text.
  3. Open TX Text Control's Page Setup dialog and choose Landscape for the orientation of the second page.
  4. Click on PrintPreview.

Note that at least TX Text Control .NET for Windows Forms 14.0 trial version and Visual Studio .NET 2005 are required to run this sample.

 
 

Products

Support

Downloads

Corporate

Buy Now