Share via


How to: Create Application Settings Using the Designer

Using Visual Studio, you can create new application settings and bind them to properties on your form or your form's controls, so that these settings are loaded and saved automatically at run time.

In the following procedure, you configure your application settings and bindings using the Windows Forms Property Editor. When you use this editor, Visual Studio generates a wrapper class for you that derives from ApplicationSettingsBase and exposes all of your settings as properties defined in that wrapper class. In the second procedure, you define this wrapper class manually.

Note

Visual Studio 2005 users can add settings to their application using the Project Designer by adding a .settings file to their applications. In Visual Basic, this will expose all settings in the My.Settings object; other languages will generate a Settings class which exposes these settings. You can create a .settings file in Visual Studio by using the Settings tab on the Project Designer to create project settings.

The Project Designer in Microsoft Visual Basic 2005 contains more options with working with application settings than the other languages in Microsoft Visual Studio 2005 . For more information, see Managing Application Settings.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To create new Application Settings using Visual Studio

  1. Select the form or control whose properties you want to bind to the new application setting.

  2. In the Property Editor, expand the (Application Settings) item, and then click the ellipsis next to the (PropertyBindings) item underneath it.

  3. In the Application Settings dialog box, click the drop-down menu for the property you want to bind and select the New command.

    Important noteImportant Note:

    The Designer will not display properties whose type is defined within the current assembly. This is a known limitation. To bind to such a property, use perform one of the following steps:

    • Move the definition of the property type to another project, build the project, and then add a reference to that new assembly to the current project. The property should then be listed in the Application Settings dialog box.

      -or-

    • Instead of using the Designer, create the application setting programmatically. For more information about this option, see How to: Create Application Settings.

  4. In the New Application Setting dialog box, configure the setting by giving it a name and a default value (if applicable) and setting its scope. If you set the scope as Application, the property will be global to all users of the application, but will likely not be alterable at run time. If you set the scope to User, the property will be read/write and its value may differ from user to user. For more information about settings scope, see Application Settings Overview.

  5. If your setting will contain a connection string, select the Connection String check box on the dialog box.

  6. Click OK on both the New Application Setting dialog box and the Application Settings dialog box. You have now successfully created a new application setting and bound it to the specified property.

  7. To manipulate individual application settings, access the properties of the My.Settings object in Visual Basic, or the Settings object in other languages. For example, in languages other than Visual Basic, you must explicitly call the Save method of this wrapper class in order to persist the user settings. This is usually done in the Closing event handler of the main form. In Visual Basic, the designer will automatically generate code to save the current values of all the user settings during application shutdown.

Security

The default settings provider, LocalFileSettingsProvider, persists information to configuration files as plain text. This limits security to the file access security provided by the operating system for the current user. Because of this, care must be taken with the information stored in configuration files. For example, one common use for application settings is to store connection strings that point to the application's data store. However, because of security concerns, such strings should not include passwords. For more information about connection strings, see SpecialSetting.

See Also

Tasks

How to: Create Application Settings

How to: Validate Application Settings

Concepts

Application Settings Overview

Reference

LocalFileSettingsProvider