User Settings and Application Settings
What is Application Settings and User Settings
Application Settings and User Settings was first introduce in .net framework 2.0 wherein we can create and access values that are persisted between application execution sessions. Settings can represent user preferences, or valuable data that can be use on the entire application.
Using Application Settings and User Settings is one mechanisms for programmers to easily store settings and access them in memory whenever needed. You can store user define color, theme and connection string to your database. Application Settings and User Settings can be stored as any data type that can be serialized to XML or has a TypeConverter that implements ToString/FromString.
Check out Modern UI Design Project Tutorial No. 2 to see on how I use Settings.
Using Application Settings and User Settings
When we create a new windows forms project in Visual Studio there is a folder called Properties. Inside that older you can see a Settings.settings file. We need to select and double-click that Settings.settings file to open the settings table.
Choosing between Application Settings and User Settings
If you will check on the table above there is a Scope column. Setting it between application/user indicates whether the setting will be changed by the user or not. The user setting is reset every each user installation.
Application – It is read only and cannot be change by user. It is constant in every instance of the application.
User – it is not read only and can be changed by whenever needed. Reset every each user installation
How to Retrieve and Update Application and User Settings
Example we created setting with a name Database, we can retrieve the value assigned to that settings by using the code below :
inputBox.Text = Properties.<u>Settings</u>.Default.SavedInputString;
inputBox.Text = Properties.<u>Settings</u>.Default.SavedInputString
When we change value of a user setting, we just need to use the code below to save our changes :