Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Windows Forms PrintPreviewDialog control is a preconfigured dialog box used to display how a PrintDocument appears 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 true
.
Certain properties are available through the PrintPreviewControl that the PrintPreviewDialog contains. (You don't have to add PrintPreviewControl to the form; it's 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++.
PrintPreviewDialog performance
Under the following conditions, the PrintPreviewDialog control initializes slowly:
- A network printer is used.
- User preferences for this printer, such as duplex settings, are modified.
The optimization isn't applied if you use the QueryPageSettings event to modify page settings.
To apply the optimization, set the Switch.System.Drawing.Printing.OptimizePrintPreview
runtime config option to true
.
The option can be set in the runtimeconfig.json configuration file or the project file of an app:
Configure a default in project file.
To apply the setting in the project file, enable runtime config generation by setting
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
to in a<PropertyGroup>
. Then, add the<RuntimeHostConfigurationOption>
setting to an<ItemGroup>
:<Project Sdk="Microsoft.NET.Sdk"> <!-- Other project settings ... --> <PropertyGroup> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> </PropertyGroup> <ItemGroup> <RuntimeHostConfigurationOption Include="Switch.System.Drawing.Printing.OptimizePrintPreview" Value="true" /> </ItemGroup> </Project>
Configure a default in the runtimeconfig.template.json source file.
To configure the default setting for your app, apply the setting in the runtimeconfig.template.json source file. When the app is compiled or published, the template file is used to generate a runtime config file.
{ "configProperties": { "Switch.System.Drawing.Printing.OptimizePrintPreview": true } }
For more information about runtime config, see .NET runtime configuration settings.
Configure a published app with the {appname}.runtimeconfig.json output file.
To configure the published app, apply the setting in the {appname}.runtimeconfig.json file's
runtimeOptions/configProperties
section.{ "runtimeOptions": { "configProperties": { "Switch.System.Drawing.Printing.OptimizePrintPreview": true, } } }
For more information about runtime config, see .NET runtime configuration settings.
See also
.NET Desktop feedback