Skip to content

Commit 06658b4

Browse files
authored
Merge pull request #2064 from dotnet/main
Publish
2 parents 0606a2f + 7ab6dde commit 06658b4

File tree

133 files changed

+593
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+593
-600
lines changed

dotnet-desktop-guide/framework/winforms/controls/printpreviewdialog-control-overview-windows-forms.md

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "PrintPreviewDialog Control Overview"
3-
description: This article provides an overview of the PrintPreviewDialog control in Windows Forms, which is a pre-configured dialog box.
4-
ms.date: "01/08/2018"
3+
description: This article provides an overview of the PrintPreviewDialog control in Windows Forms, which is a preconfigured dialog box.
4+
ms.date: 04/07/2025
55
f1_keywords:
66
- "PrintPreviewDialog"
77
helpviewer_keywords:
@@ -10,43 +10,100 @@ ms.assetid: efd4ee8d-6edd-47ec-88e4-4a4759bd2384
1010
---
1111
# PrintPreviewDialog control overview (Windows Forms)
1212

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.
1414

1515
## Key properties and methods
1616

1717
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`.
1818

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++.
2020

2121
## PrintPreviewDialog performance
2222

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:
2424

2525
- A network printer is used.
2626
- User preferences for this printer, such as duplex settings, are modified.
2727

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.
2929

30-
```xml
31-
<appSettings>
32-
<add key="EnablePrintPreviewOptimization" value="true" />
33-
</appSettings>
34-
```
30+
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>`:
39+
40+
```xml
41+
<Project Sdk="Microsoft.NET.Sdk">
42+
43+
<!-- Other project settings ... -->
44+
45+
<PropertyGroup>
46+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
47+
</PropertyGroup>
48+
49+
<ItemGroup>
50+
<RuntimeHostConfigurationOption Include="Switch.System.Drawing.Printing.OptimizePrintPreview" Value="true" />
51+
</ItemGroup>
3552

36-
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+
```
3755

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.
59+
60+
```json
61+
{
62+
"configProperties": {
63+
"Switch.System.Drawing.Printing.OptimizePrintPreview": true
64+
}
65+
}
66+
```
67+
68+
For more information about runtime config, see [.NET runtime configuration settings](/dotnet/core/runtime-config/).
69+
70+
- **Configure a published app with the _{appname}.runtimeconfig.json_ output file.**
71+
72+
To configure the published app, apply the setting in the _{appname}.runtimeconfig.json_ file's `runtimeOptions/configProperties` section.
73+
74+
```json
75+
{
76+
"runtimeOptions": {
77+
"configProperties": {
78+
"Switch.System.Drawing.Printing.OptimizePrintPreview": true,
79+
}
80+
}
81+
}
82+
```
83+
84+
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:
3989

4090
```xml
4191
<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" -->
93+
<AppContextSwitchOverrides value="Switch.System.Drawing.Printing.OptimizePrintPreview=true" />
4494
</runtime >
4595
```
4696

47-
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:
99+
>
100+
> ```xml
101+
> <appSettings>
102+
> <add key="EnablePrintPreviewOptimization" value="true" />
103+
> </appSettings>
104+
> ```
48105
49-
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.
106+
---
50107
51108
## See also
52109

dotnet-desktop-guide/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ metadata:
1010
ms.product: dotnet
1111
author: adegeo
1212
ms.author: adegeo
13-
ms.date: 11/11/2024
13+
ms.date: 04/02/2025
1414

1515
# linkListType: architecture | concept | deploy | download | get-started | how-to-guide | learn | overview | quickstart | reference | sample | tutorial | video | whats-new
1616

dotnet-desktop-guide/net/winforms/controls-design/designer-differences-framework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Designers changes from .NET Framework
33
description: Learn about the Windows Forms designer changes from .NET Framework to .NET.
4-
ms.date: 11/14/2024
4+
ms.date: 04/02/2025
55
ms.topic: overview
66
no-loc: ["UserControl", "UserControl1", "UserControlProject", "Label", "Button", "Form", "TextBox"]
77
dev_langs:

dotnet-desktop-guide/net/winforms/controls-design/designer-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Design-time error troubleshooting
33
description: Learn about some of the common errors that occur when the Windows Forms Designer fails to load. This article might help you troubleshoot those errors.
4-
ms.date: 07/19/2023
4+
ms.date: 04/01/2025
55
ms.topic: troubleshooting
66
f1_keywords:
77
- "DTELErrorList"

dotnet-desktop-guide/net/winforms/controls-design/designer-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Visual Studio Design-time overview
33
description: Learn about what capabilities are available in Visual Studio for Windows Forms designer support with your custom controls.
4-
ms.date: 06/01/2023
4+
ms.date: 04/01/2025
55
ms.topic: overview
66
no-loc: ["UserControl", "UserControl1", "UserControlProject", "Label", "Button", "Form", "TextBox"]
77
dev_langs:
@@ -30,7 +30,7 @@ Many basic design elements of custom controls have remained the same from .NET F
3030

3131
Visual Studio is a .NET Framework-based application, and as such, the Visual Designer you see for Windows Forms is also based on .NET Framework. With a .NET Framework project, both the Visual Studio environment and the Windows Forms app being designed run within the same process, **devenv.exe**. This poses a problem when you're working with a Windows Forms .NET (not .NET Framework) app. Both .NET and .NET Framework can't work within the same process. As a result, Windows Forms .NET uses a different designer, the "out-of-process" designer.
3232

33-
The out-of-process designer is a process called **DesignToolsServer.exe**, and is run along-side Visual Studio's **devenv.exe** process. The **DesignToolsServer.exe** process runs in the same version and platform, such as .NET 9 and x64, of .NET that your app is targeting. When your custom control needs to display UI in the **devenv.exe** your custom control must implement a client-server architecture to facilitate the communication to and from **devenv.exe**. For more information, see [The designer changes since .NET Framework (Windows Forms .NET)](designer-differences-framework.md).
33+
The out-of-process designer is a process called **DesignToolsServer.exe**, and is run alongside Visual Studio's **devenv.exe** process. The **DesignToolsServer.exe** process runs in the same version and platform, such as .NET 9 and x64, of .NET that your app is targeting. When your custom control needs to display UI in Visual Studio, your custom control must implement a client-server architecture to facilitate the communication to and from **devenv.exe**. For more information, see [The designer changes since .NET Framework](designer-differences-framework.md).
3434

3535
## Property window
3636

dotnet-desktop-guide/net/winforms/controls-design/designer-properties-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Design-time properties overview
33
description: Learn about how the Windows Forms Designer interacts with control and form properties during design-time.
4-
ms.date: 07/14/2023
4+
ms.date: 04/02/2025
55
ms.topic: overview
66
no-loc: ["UserControl"]
77
dev_langs:
@@ -123,4 +123,4 @@ This should be converted into examples
123123
The **Properties** window automatically uses a type editor for a property when the type of the property is a built-in or known type. For example, a boolean value is edited as a combo box with **True** and **False** values and the <xref:System.DateTime> type uses a calendar dropdown.
124124

125125
> [!IMPORTANT]
126-
> Custom type editors have changed since .NET Framework. For more information, see [The designer changes since .NET Framework (Windows Forms .NET)](designer-differences-framework.md).
126+
> Custom type editors have changed since .NET Framework. For more information, see [The designer changes since .NET Framework](designer-differences-framework.md).

dotnet-desktop-guide/net/winforms/controls-design/how-to-create-usercontrol.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: How to create a user control
33
description: This article teaches you how to create a user control, known as a composite control, that you can add to other forms.
4-
ms.date: 06/19/2023
4+
ms.date: 04/02/2025
55
ms.topic: how-to
66
no-loc: ["UserControl", "UserControl1", "UserControlProject", "Label", "Button", "Form", "TextBox"]
77
dev_langs:
@@ -47,6 +47,7 @@ The user control is made up of _constituent controls_, which are the controls yo
4747
01. With the designer open, the user control design surface should be the selected object. If it's not, click on the design surface to select it. Set the following properties in the **Properties** window:
4848

4949
> [!div class="mx-tableNormal"]
50+
>
5051
> | Property | Value |
5152
> |-------------|------------|
5253
> | MinimumSize | `84, 53` |
@@ -55,6 +56,7 @@ The user control is made up of _constituent controls_, which are the controls yo
5556
01. Add a **Label** control. Set the following properties:
5657

5758
> [!div class="mx-tableNormal"]
59+
>
5860
> | Property | Value |
5961
> |----------|------------|
6062
> | Name | `lblTitle` |
@@ -63,6 +65,7 @@ The user control is made up of _constituent controls_, which are the controls yo
6365
01. Add a **TextBox** control. Set the following properties:
6466

6567
> [!div class="mx-tableNormal"]
68+
>
6669
> | Property | Value |
6770
> |----------|------------|
6871
> | Name | `txtValue` |
@@ -73,6 +76,7 @@ The user control is made up of _constituent controls_, which are the controls yo
7376
01. Add a **Button** control. Set the following properties:
7477

7578
> [!div class="mx-tableNormal"]
79+
>
7680
> | Property | Value |
7781
> |----------|------------|
7882
> | Name | `btnClear` |
@@ -132,6 +136,7 @@ If you created a new project in the last section, you have a blank Form named **
132136
01. Select one control and set the following properties:
133137

134138
> [!div class="mx-tableNormal"]
139+
>
135140
> | Property | Value |
136141
> |----------|----------------|
137142
> | Name | `ctlFirstName` |
@@ -142,6 +147,7 @@ If you created a new project in the last section, you have a blank Form named **
142147
01. Select the other control and set the following properties:
143148

144149
> [!div class="mx-tableNormal"]
150+
>
145151
> | Property | Value |
146152
> |----------|---------------|
147153
> | Name | `ctlLastName` |
@@ -152,6 +158,7 @@ If you created a new project in the last section, you have a blank Form named **
152158
01. Back in the **Toolbox** window, add a label control to the form, and set the following properties:
153159

154160
> [!div class="mx-tableNormal"]
161+
>
155162
> | Property | Value |
156163
> |----------|---------------|
157164
> | Name | `lblFullName` |

dotnet-desktop-guide/net/winforms/controls-design/how-to-designer-properties-shouldserialize-reset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: How to use the Reset and ShouldSerialize methods
33
description: Learn how to implement the Reset and ShouldSerialize methods to control a property during design-time in Windows Forms.
4-
ms.date: 07/20/2023
4+
ms.date: 04/02/2025
55
ms.topic: how-to
66
dev_langs:
77
- "csharp"

dotnet-desktop-guide/net/winforms/controls-design/how-to-set-toolbox-icon.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: How to set the toolbox icon
33
description: Learn how to assign your control's icon. The icon appears in the Visual Studio Toolbox.
4-
ms.date: 07/20/2023
4+
ms.date: 04/02/2025
55
ms.topic: how-to
66
dev_langs:
77
- "csharp"

dotnet-desktop-guide/net/winforms/controls-design/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create custom controls overview
33
description: Learn about the different types of custom controls you can create in Windows Forms for .NET.
4-
ms.date: 06/01/2023
4+
ms.date: 04/02/2025
55
ms.topic: overview
66
f1_keywords:
77
- "UserControl"
@@ -117,7 +117,7 @@ If you need to implement a custom design-time experience, you can author your ow
117117

118118
Use the <xref:System.ComponentModel.DesignerAttribute> to associate your control with your designer.
119119

120-
The following information is out of date but may help you.
120+
The following information is out of date but it might help you.
121121

122122
- [(Visual Studio 2013) Extending Design-Time Support](/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120)).
123123
- [(Visual Studio 2013) How to: Create a Windows Forms Control That Takes Advantage of Design-Time Features](/previous-versions/visualstudio/visual-studio-2013/307hck25(v=vs.120)).

dotnet-desktop-guide/net/winforms/controls-design/snippets/designer-properties-overview/csharp/CompassRose.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public partial class CompassRose : UserControl
1414

1515
// <browsable>
1616
[Browsable(false)]
17+
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1718
public bool IsSelected { get; set; }
1819
// </browsable>
1920

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net7.0-windows</TargetFramework>
4+
<TargetFramework>net9.0-windows</TargetFramework>
65
<Nullable>enable</Nullable>
76
<UseWindowsForms>true</UseWindowsForms>
87
<ImplicitUsings>enable</ImplicitUsings>
98
</PropertyGroup>
10-
119
</Project>

dotnet-desktop-guide/net/winforms/controls-design/snippets/designer-properties-overview/vb/CompassRose.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Public Class CompassRose
1212

1313
'<browsable>
1414
<Browsable(False)>
15+
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
1516
Public Property IsSelected As Boolean
1617
'</browsable>
1718

Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net7.0-windows</TargetFramework>
4+
<TargetFramework>net9.0-windows</TargetFramework>
65
<StartupObject>Sub Main</StartupObject>
76
<UseWindowsForms>true</UseWindowsForms>
87
<MyType>WindowsForms</MyType>
98
<RootNamespace>UserControlProject</RootNamespace>
109
</PropertyGroup>
11-
1210
<ItemGroup>
1311
<Import Include="System.Data" />
1412
<Import Include="System.Drawing" />
1513
<Import Include="System.Windows.Forms" />
1614
</ItemGroup>
17-
1815
<ItemGroup>
1916
<Compile Update="My Project\Application.Designer.vb">
2017
<DesignTime>True</DesignTime>
2118
<AutoGen>True</AutoGen>
2219
<DependentUpon>Application.myapp</DependentUpon>
2320
</Compile>
2421
</ItemGroup>
25-
2622
<ItemGroup>
2723
<None Update="My Project\Application.myapp">
2824
<Generator>MyApplicationCodeGenerator</Generator>
2925
<LastGenOutput>Application.Designer.vb</LastGenOutput>
3026
</None>
3127
</ItemGroup>
32-
3328
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net8.0-windows</TargetFramework>
4+
<TargetFramework>net9.0-windows</TargetFramework>
65
<Nullable>enable</Nullable>
76
<UseWindowsForms>true</UseWindowsForms>
87
<ImplicitUsings>enable</ImplicitUsings>
98
</PropertyGroup>
10-
119
</Project>

0 commit comments

Comments
 (0)