
Accessing or Changing Application Settings at Run Time in Visual Basic
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. (For more information, see How to: Access Settings Events.) Settings.vb defines the Settings class, which enables you to handle these events on the settings class: SettingChanging, PropertyChanged, SettingsLoaded, and 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 Accessing Application Settings.
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.
If you have changed any user-scoped settings during run time, for example in testing the application, and want to reset these settings to their default values, click the Synchronize button. For information about this control, see Settings Page, Project Designer.
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 also save the user settings before ending the application, as you would do for a C# application; this is described in the following section.