Home » C# Basics » 09 - Windows Programming - 2
9

Windows common dialogs - PrintDialog

Explains how to integrate the windows common task "printdialog box" in our application.

The PrintPreviewDialog gives the users an option to preview the document before printing so that they can see how the document will look in print. Implementing the PrintPreviewDialog is very simple.

  • Drag the PrintPreviewDialog from the Printing section of the Toolbox and drop it on the form. The control will be added to the control tray. The default name for the control is printPreviewDialog1. Make sure that the printDocument1 control (added in the previous section) is present.
  • Select the printPreviewDialog1 control in the control tray. Set its Document property to printDocument1 from the properties window.
  • In the click event of the Print Preview menu option (and also in the click event of the Print Preview toolbar button), type the following code:
 private void mnuFilePrintPreview_Click(object sender, EventArgs e) { printPreviewDialog1.ShowDialog(); }

Save and run the application. When the user clicks on the Print Preview menu option (or toolbar button), the print preview dialog will be displayed. The dialog has a close button to close the preview and return to the document.