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
Copy file name to clipboardExpand all lines: docs/ide/managing-application-settings-dotnet.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
title: Manage application settings (.NET)
3
-
description: Learn how to manage application settings (formerly called dynamic properties) that are not included in the application code, but are needed at runtime.
3
+
description: Learn how to manage application settings (formerly called dynamic properties) that aren't included in the application code, but are needed at runtime.
4
4
ms.custom: SEO-VS-2020
5
-
ms.date: 11/04/2016
5
+
ms.date: 02/14/2022
6
6
ms.topic: conceptual
7
7
f1_keywords:
8
8
- msvse_settingsdesigner.err.nameblank
@@ -17,11 +17,11 @@ ms.workload:
17
17
---
18
18
# Manage application settings (.NET)
19
19
20
-
Application settings enable you to store application information dynamically. Settings allow you to store information on the client computer that should not be included in the application code (for example a connection string), user preferences, and other information you need at run time.
20
+
Application settings enable you to store application information dynamically. Settings allow you to store information on the client computer that shouldn't be included in the application code (for example a connection string), user preferences, and other information you need at runtime.
21
21
22
22
Application settings replace the dynamic properties used in earlier versions of Visual Studio.
23
23
24
-
Each application setting must have a unique name. The name can be any combination of letters, numbers, or an underscore that does not start with a number, and it cannot have spaces. The name is changed through the `Name` property.
24
+
Each application setting must have a unique name. The name can be any combination of letters, numbers, or an underscore that doesn't start with a number, and it can't have spaces. The name is changed through the `Name` property.
25
25
26
26
Application settings can be stored as any data type that is serialized to XML or has a `TypeConverter` that implements `ToString`/`FromString`. The most common types are `String`, `Integer`, and `Boolean`, but you can also store values as <xref:System.Drawing.Color>, <xref:System.Object>, or as a connection string.
27
27
@@ -31,19 +31,19 @@ In addition, application settings can be bound to a property of a form or contro
31
31
32
32
There are two types of application settings, based on scope:
33
33
34
-
- Application-scoped settings can be used for information such as a URL for a web service or a database connection string. These values are associated with the application. Therefore, users cannot change them at run time.
34
+
- Application-scoped settings can be used for information such as a URL for a web service or a database connection string. These values are associated with the application. Therefore, users can't change them at runtime.
35
35
36
-
- User-scoped settings can be used for information such as persisting the last position of a form or a font preference. Users can change these values at run time.
36
+
- User-scoped settings can be used for information such as persisting the last position of a form or a font preference. Users can change these values at runtime.
37
37
38
38
You can change the type of a setting by using the **Scope** property.
39
39
40
40
The project system stores application settings in two XML files:
41
41
42
42
- an *app.config* file, which is created at design time when you create the first application setting
43
43
44
-
- a *user.config* file, which is created at run time when the user who runs the application changes the value of any user setting.
44
+
- a *user.config* file, which is created at runtime when the user who runs the application changes the value of any user setting.
45
45
46
-
Notice that changes in user settings are not written to disk unless the application specifically calls a method to do this.
46
+
Notice that changes in user settings aren't written to disk unless the application specifically calls a method to do this.
47
47
48
48
## Create application settings at design time
49
49
@@ -67,22 +67,22 @@ When you create a user-scoped setting (for example, default font, home page, or
67
67
68
68
You can add customized settings files to your project for convenient management of groups of settings. Settings that are contained in a single file are loaded and saved as a unit. Storing settings in separate files for frequently used and infrequently used groups can save time in loading and saving settings.
69
69
70
-
For example, you can add a file such as *SpecialSettings.settings* to your project. While your `SpecialSettings` class is not exposed in the `My` namespace, **View Code** can read the custom settings file that contains `Partial Class SpecialSettings`.
70
+
For example, you can add a file such as *SpecialSettings.settings* to your project. While your `SpecialSettings` class isn't exposed in the `My` namespace, **View Code** can read the custom settings file that contains `Partial Class SpecialSettings`.
71
71
72
-
The **Settings Designer** first searches for the *Settings.settings* file that the project system creates; this file is the default file that the **Project Designer** displays in the **Settings** tab. *Settings.settings* is located in the *My Project* folder for [!INCLUDE[vbprvb](../code-quality/includes/vbprvb_md.md)] projects and in the *Properties* folder for [!INCLUDE[csprcs](../data-tools/includes/csprcs_md.md)] projects. The **Project Designer** then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there. If you add a *.settings* file elsewhere in your project, the **Project Designer**will not be able to locate it.
72
+
The **Settings Designer** first searches for the *Settings.settings* file that the project system creates; this file is the default file that the **Project Designer** displays in the **Settings** tab. *Settings.settings* is located in the *My Project* folder for [!INCLUDE[vbprvb](../code-quality/includes/vbprvb_md.md)] projects and in the *Properties* folder for [!INCLUDE[csprcs](../data-tools/includes/csprcs_md.md)] projects. The **Project Designer** then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there. If you add a *.settings* file elsewhere in your project, the **Project Designer**won't be able to locate it.
73
73
74
-
## Access or change application settings at run time in Visual Basic
74
+
## Access or change application settings at runtime in Visual Basic
75
75
76
-
In Visual Basic projects, you can access application settings at run time by using the `My.Settings` object. On the **Settings** page, click the **View code** button to view the *Settings.vb* file. *Settings.vb* defines the `Settings` class, which enables you to handle these events on the settings class: <xref:System.Configuration.ApplicationSettingsBase.SettingChanging>, <xref:System.Configuration.ApplicationSettingsBase.PropertyChanged>, <xref:System.Configuration.ApplicationSettingsBase.SettingsLoaded>, and <xref:System.Configuration.ApplicationSettingsBase.SettingsSaving>. Notice that the `Settings` class in *Settings.vb* is a partial class that displays only the user-owned code, not the whole generated class. For more information about accessing application settings by using the `My.Settings` object, see [Access application settings (.NET Framework)](/dotnet/visual-basic/developing-apps/programming/app-settings/accessing-application-settings).
76
+
In Visual Basic projects, you can access application settings at runtime by using the `My.Settings` object. On the **Settings** page, click the **View code** button to view the *Settings.vb* file. *Settings.vb* defines the `Settings` class, which enables you to handle these events on the settings class: <xref:System.Configuration.ApplicationSettingsBase.SettingChanging>, <xref:System.Configuration.ApplicationSettingsBase.PropertyChanged>, <xref:System.Configuration.ApplicationSettingsBase.SettingsLoaded>, and <xref:System.Configuration.ApplicationSettingsBase.SettingsSaving>. Notice that the `Settings` class in *Settings.vb* is a partial class that displays only the user-owned code, not the whole generated class. For more information about accessing application settings by using the `My.Settings` object, see [Access application settings (.NET Framework)](/dotnet/visual-basic/developing-apps/programming/app-settings/accessing-application-settings).
77
77
78
-
The values of any user-scoped settings that the user changes at run time (for example, the position of a form) are stored in a *user.config* file. Notice that the default values are still saved in *app.config*.
78
+
The values of any user-scoped settings that the user changes at runtime (for example, the position of a form) are stored in a *user.config* file. Notice that the default values are still saved in *app.config*.
79
79
80
-
If any user-scoped settings are changed during run time, for example in testing the application, and want to reset these settings to their default values, click the **Synchronize** button.
80
+
If any user-scoped settings are changed during runtime, for example in testing the application, and want to reset these settings to their default values, click the **Synchronize** button.
81
81
82
82
We strongly recommend that you use the `My.Settings` object and the default *.settings* file to access settings. This is because you can use the **Settings Designer** to assign properties to settings, and, additionally, user settings are automatically saved before application shutdown. However, your Visual Basic application can access settings directly. In that case you have to access the `MySettings` class and use a custom *.settings* file in the root of the project. You must save the user settings before ending the application, as you would do for a C# application; this is described in the following section.
83
83
84
84
<!-- markdownlint-disable MD003 MD020 -->
85
-
## Access or change application settings at run time in C#
85
+
## Access or change application settings at runtime in C#
86
86
<!-- markdownlint-enable MD003 MD020 -->
87
87
88
88
In languages other than Visual Basic, such as C#, you must access the `Settings` class directly, as shown in the following [!INCLUDE[csprcs](../data-tools/includes/csprcs_md.md)] example.
0 commit comments