You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# PrintPreviewDialog control overview (Windows Forms)
12
12
13
-
The Windows Forms <xref:System.Windows.Forms.PrintPreviewDialog> control is a pre-configured dialog box used to display how a [PrintDocument](printdocument-component-windows-forms.md)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.
13
+
The Windows Forms <xref:System.Windows.Forms.PrintPreviewDialog> control is a preconfigured dialog box used to display how a [PrintDocument](printdocument-component-windows-forms.md)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.
14
14
15
15
## Key properties and methods
16
16
17
17
The control's key property is <xref:System.Windows.Forms.PrintPreviewDialog.Document%2A>, which sets the document to be previewed. The document must be a <xref:System.Drawing.Printing.PrintDocument> object. In order to display the dialog box, you must call its <xref:System.Windows.Forms.Form.ShowDialog%2A> method. Anti-aliasing can make the text appear smoother, but it can also make the display slower; to use it, set the <xref:System.Windows.Forms.PrintPreviewDialog.UseAntiAlias%2A> property to `true`.
18
18
19
-
Certain properties are available through the <xref:System.Windows.Forms.PrintPreviewControl> that the <xref:System.Windows.Forms.PrintPreviewDialog> contains. (You do not have to add this <xref:System.Windows.Forms.PrintPreviewControl> to the form; it is automatically contained within the <xref:System.Windows.Forms.PrintPreviewDialog> when you add the dialog to your form.) Examples of properties available through the <xref:System.Windows.Forms.PrintPreviewControl> are the <xref:System.Windows.Forms.PrintPreviewControl.Columns%2A> and <xref:System.Windows.Forms.PrintPreviewControl.Rows%2A> properties, which determine the number of pages displayed horizontally and vertically on the control. You can access the <xref:System.Windows.Forms.PrintPreviewControl.Columns%2A> property as `PrintPreviewDialog1.PrintPreviewControl.Columns` in Visual Basic, `printPreviewDialog1.PrintPreviewControl.Columns` in Visual C#, or `printPreviewDialog1->PrintPreviewControl->Columns` in Visual C++.
19
+
Certain properties are available through the <xref:System.Windows.Forms.PrintPreviewControl> that the <xref:System.Windows.Forms.PrintPreviewDialog> contains. (You don't have to add <xref:System.Windows.Forms.PrintPreviewControl> to the form; it's automatically contained within the <xref:System.Windows.Forms.PrintPreviewDialog> when you add the dialog to your form.) Examples of properties available through the <xref:System.Windows.Forms.PrintPreviewControl> are the <xref:System.Windows.Forms.PrintPreviewControl.Columns%2A> and <xref:System.Windows.Forms.PrintPreviewControl.Rows%2A> properties, which determine the number of pages displayed horizontally and vertically on the control. You can access the <xref:System.Windows.Forms.PrintPreviewControl.Columns%2A> property as `PrintPreviewDialog1.PrintPreviewControl.Columns` in Visual Basic, `printPreviewDialog1.PrintPreviewControl.Columns` in Visual C#, or `printPreviewDialog1->PrintPreviewControl->Columns` in Visual C++.
20
20
21
21
## PrintPreviewDialog performance
22
22
23
-
Under the following conditions, the <xref:System.Windows.Forms.PrintPreviewDialog> control initializes very slowly:
23
+
Under the following conditions, the <xref:System.Windows.Forms.PrintPreviewDialog> control initializes slowly:
24
24
25
25
- A network printer is used.
26
26
- User preferences for this printer, such as duplex settings, are modified.
27
27
28
-
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 <xref:System.Windows.Forms.PrintPreviewDialog> control initialization:
28
+
The optimization isn't applied if you use the <xref:System.Drawing.Printing.PrintDocument.QueryPageSettings> event to modify page settings.
To apply the optimization, set the `Switch.System.Drawing.Printing.OptimizePrintPreview` runtime config option to `true`.
31
+
32
+
# [.NET](#tab/dotnet)
33
+
34
+
The option can be set in the _runtimeconfig.json_ configuration file or the project file of an app:
35
+
36
+
-**Configure a default in project file.**
37
+
38
+
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>`:
If the `EnablePrintPreviewOptimization` key is set to any other value, or if the key is not present, the optimization is not applied. This key has no effect if the application is running on .NET Framework 4.6 or later.
53
+
</Project>
54
+
```
37
55
38
-
For apps running on the .NET Framework 4.6 or later versions, you can add the following switch to the [\<AppContextSwitchOverrides>](/dotnet/framework/configure-apps/file-schema/runtime/appcontextswitchoverrides-element) element in the [\<runtime>](/dotnet/framework/configure-apps/file-schema/runtime/index) section of your app config file:
56
+
-**Configure a default in the _runtimeconfig.template.json_ source file.**
57
+
58
+
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.
For more information about runtime config, see [.NET runtime configuration settings](/dotnet/core/runtime-config/).
85
+
86
+
# [.NET Framework](#tab/dotnetframework)
87
+
88
+
Add the following switch to the [`<AppContextSwitchOverrides>`](/dotnet/framework/configure-apps/file-schema/runtime/appcontextswitchoverrides-element) element in the [`<runtime>`](/dotnet/framework/configure-apps/file-schema/runtime/index) section of the app config file:
39
89
40
90
```xml
41
91
<runtime >
42
-
<!-- AppContextSwitchOverrides values are in the form of 'key1=true|false;key2=true|false -->
43
-
<AppContextSwitchOverrides value = "Switch.System.Drawing.Printing.OptimizePrintPreview=true" />
92
+
<!-- AppContextSwitchOverrides values are in the form of "key1=true|false;key2=true|false"-->
If the switch is not present or if it is set to any other value, the optimization is not applied.
97
+
> [!TIP]
98
+
> If .NET Framework 4.5.2 (no longer supported) is installed, enable the optimization by adding the following key to the `<appSettings>` section of your configuration file to improve the performance of <xref:System.Windows.Forms.PrintPreviewDialog> control initialization:
If you use the <xref:System.Drawing.Printing.PrintDocument.QueryPageSettings> event to modify printer settings, the performance of the <xref:System.Windows.Forms.PrintPreviewDialog> control will not improve even if an optimization configuration switch is set.
0 commit comments