Print Preview


You can use Print Preview so that the user can see what the printout will look like. Implementing Print Preview can be easily done in .NET — you can use a PrintPreviewControl class that is used to preview the document inside a form to show how it will be printed. the PrintPreviewDialog is a dialog that wraps the control.

PrintPreviewDialog

If you look at the properties and inheritance list from the MSDN documentation of the PrintPreviewDialog class, you can see that it is actually a Form and not a wrapped common dialog — the class derives from System.Windows.Forms.Form, and you can work with it as with the forms you created in Chapter 15.

In the following Try It Out, you add a PrintPreviewDialog class to the Simple Editor application.

Try It Out – Adding a PrintPreviewDialog

image from book
  1. Add a PrintPreviewDialog component from the Toolbox onto the Windows Forms designer. Set the Name to dlgPrintPreview and the Document property to printDocument.

  2. Add and implement a handler for the Click event of the Print Preview menu entry.

    private void OnFilePrintPreview(object sender, EventArgs e) { dlgPrintPreview.ShowDialog(); }
  3. Starting the application, you can see the Print preview, as shown in Figure 16-26.

    image from book
    Figure 16-26

image from book

PrintPreviewControl

The print preview in Microsoft Word and WordPad is different from the PrintPreviewDialog in so far as the preview in these applications doesn't show up in its own dialog, but in the main window of the application.

To do the same, you can place the PrintPreviewControl class in your form. the Document property must be set to the printDocument object, and the Visible property to false — when you want to display the print preview, you simply set the Visible property to true. Then the PrintPreviewControl is in front of the other control, as shown in Figure 16-27.

image from book
Figure 16-27

You can see from the title and the single File menu item that it is the main window of the Simple Editor application that is displayed. You still need to add some elements to control the PrintPreviewControl class to do zooming, printing, and to display several pages of text at once. A specific toolbar can be used to make these features available. the PrintPreviewDialog class already has this implemented as you can see from the four-page preview shown in Figure 16-28.

image from book
Figure 16-28




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net