PrintPreviewDialog control overview (Windows Forms)
The Windows Forms PrintPreviewDialog control is a pre-configured dialog box used to display how a PrintDocument will appear when printed. Use it within your Windows-based application as a simple solution instead of configuring your own dialog box. The control contains buttons for printing, zooming in, displaying one or multiple pages, and closing the dialog box.
Key properties and methods
The control's key property is Document, which sets the document to be previewed. The document must be a PrintDocument object. In order to display the dialog box, you must call its ShowDialog method. Anti-aliasing can make the text appear smoother, but it can also make the display slower; to use it, set the UseAntiAlias property to
Certain properties are available through the PrintPreviewControl that the PrintPreviewDialog contains. (You do not have to add this PrintPreviewControl to the form; it is automatically contained within the PrintPreviewDialog when you add the dialog to your form.) Examples of properties available through the PrintPreviewControl are the Columns and Rows properties, which determine the number of pages displayed horizontally and vertically on the control. You can access the Columns property as
PrintPreviewDialog1.PrintPreviewControl.Columns in Visual Basic,
printPreviewDialog1.PrintPreviewControl.Columns in Visual C#, or
printPreviewDialog1->PrintPreviewControl->Columns in Visual C++.
Under the following conditions, the PrintPreviewDialog control initializes very slowly:
- A network printer is used.
- User preferences for this printer, such as duplex settings, are modified.
For apps running on the .NET Framework 4.5.2, you can add the following key to the <appSettings> section of your configuration file to improve the performance of PrintPreviewDialog control initialization:
<appSettings> <add key="EnablePrintPreviewOptimization" value="true" /> </appSettings>
EnablePrintPreviewOptimization key is set to any other value, or if the key is not present, the optimization is not applied.
<runtime > <!-- AppContextSwitchOverrides values are in the form of 'key1=true|false;key2=true|false --> <AppContextSwitchOverrides value = "Switch.System.Drawing.Printing.OptimizePrintPreview=true" /> </runtime >
If the switch is not present or if it is set to any other value, the optimization is not applied.
Send feedback about: