Visual Basic 2005 with .NET 3.0 Programmer's Reference

The PrintPreviewDialog component displays a dialog box that shows what a print document will look like when it is printed. You can use this component to display a print preview dialog similar to the one shown in Figure G-19. This dialog box contains a PrintPreviewControl, plus some extra tools to let the user control the preview.

Figure G-19: The PrintPreviewDialog component lets you easily display a full-featured print preview dialog box.

The tools that run from left to right across the top of the dialog box automatically give the user the following features:

The dialog box’s most important property is Document. This property determines the PrintDocument object that the dialog box previews. See the section “PrintDocument” earlier in this appendix for more information about this class.

The component’s most important methods are Show, which displays the dialog box, and ShowDialog, which displays the dialog box modally.

Using this component is remarkably simple. Set its Document property and catch the PrintDocument object’s PrintPage event as shown in the previous section. Then display the dialog box as in the following code:

dlgPrintPreview.ShowDialog()

The rest is automatic. The dialog box lets the user move through the document’s pages, zoom in and out, and even print the document.

Категории