10.19 Displaying a Print Preview Dialog

 <  Day Day Up  >  

You want to add the ability for a user to see what the printed output will look like before he prints.


Technique

Displaying a preview of printed output is similar to the method used to show the print dialog. Create a PrintPreviewDialog object and the helper class derived from the PrintDocument class created in the previous recipe. Associate the PrintDocument object with the print preview dialog by setting the Document property of the PrintPreviewDialog to the PrintDocument instance. To display the print preview window, call the ShowDialog method of the PrintPreviewDialog object:

 
 private void menuPrintPreview_Click(object sender, System.EventArgs e) {     if( image == null )         return;     PrintPreviewDialog dlg = new PrintPreviewDialog() ;     ImagePrintDocument doc = new ImagePrintDocument( image );     dlg.Document = doc;     dlg.ShowDialog(this); } 

Comments

Creating a print preview dialog for your application can almost be considered a freebie when using the .NET Framework. If you created the PrintDocument derived class for your application for printing, you can associate that class with a PrintPreviewDialog object. The .NET Framework displays a Windows Form containing the common features associated with most print preview dialogs within Windows. This class also provides the functionality necessary to preview multiple pages at once, zoom the document within the window, and automatically print the document when the user clicks on the print button within the print preview dialog. Figure 10.5 shows a print preview dialog for the image editor application created for this chapter.

Figure 10.5. Displaying a Print Preview form.

graphics/10fig05.jpg

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

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