Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Printing into a PrintPreview control

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:C# .NET
Version:2.0
Released:March 11, 2008
Last modified:March 11, 2008
Requirements:TX Text Control .NET with Visual Studio 2005
Download code:tx_printpreview_sample.zip Download [14.09 KB, ZIP]
Click to enlarge

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.

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. PrintDocument pd = new PrintDocument();
  4. PrintPreview(pd);
  5. }

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.

  1. private void OnPrintPage(object obj, PrintPageEventArgs ppe)
  2. {
  3. // print the contents of TX Text Control
  4. textControl1.Print(m_currentPage, ppe);
  5. if (m_currentPage == textControl1.Pages)
  6. ppe.HasMorePages = false;
  7. else
  8. {
  9. ppe.HasMorePages = true;
  10. m_currentPage++;
  11. }
  12. }
  13. private void OnQueryPageSettings(object obj, QueryPageSettingsEventArgs qpe)
  14. {
  15. // retrieve the page orientation of the currently printed page
  16. textControl1.InputPosition = new TXTextControl.InputPosition(m_currentPage, 1, 0);
  17. qpe.PageSettings.Landscape = textControl1.Sections.GetItem().Format.Landscape;
  18. }

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 14.0 trial version and Visual Studio .NET 2005 are required to run this sample.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place