Udostępnij za pośrednictwem


How to: Change User Settings in Visual Basic

You can change a user setting by assigning a new value to the setting's property on the My.Settings object.

The My.Settings object exposes each setting as a property. The property name is the same as the setting name, and the property type is the same as the setting type. The setting's Scope determines if the property is read-only: The property for an Application-scope setting is read-only, while the property for a User-scope setting is read-write. For more information, see My.Settings Object.

Note

Although you can change and save the values of user-scope settings at run time, application-scope settings are read-only and cannot be changed programmatically. You can change application-scope settings when you create the application by using the Project Designer or by editing the application's configuration file. For more information, see Application Settings.

Example

This example changes the value of the Nickname user setting.

Sub ChangeNickname(ByVal newNickname As String)
    My.Settings.Nickname = newNickname
End Sub

For this example to work, your application must have a Nickname user setting, of type String. For more information, see How to: Add or Remove Application Settings.

The application saves the user settings when the application shuts down. To save the settings immediately, call the My.Settings.Save method. For more information, see How to: Persist User Settings in Visual Basic.

See Also

Tasks

How to: Read Application Settings in Visual Basic

How to: Persist User Settings in Visual Basic

How to: Create Property Grids for User Settings in Visual Basic

How to: Add or Remove Application Settings

Concepts

Application Settings

Reference

My.Settings Object

Other Resources

Managing Application Settings