Our starting application will be one of the easiest uses of settings that I can think of. We'll simply save a selected background color (BackColor) for a form. We'll use the Property window to create our application setting. A new BackColor will be selected and persisted with two lines of code in the Click event for a Button.
Step 1 - Create a new standard Windows application. Drag a Button and a ColorDialog component onto the form from the Toolbox. In the Properties window, scroll up and open the Application Settings Property Binding dialog. A binding isn't quite the same thing as a property. A binding associates an object, in this case the Form object, with some other data. The BackColor property of the Form is actually bound to the Application Setting.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Step 2 - Click the "ellipsis" button (with the three dots) to open the Application Settings for Form1 dialog window. Scroll up to find the BackColor property. Click the down arrow for the BackColor property value and then click the New ... link at the bottom.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Step 3 - In the New Application Setting dialog, give your setting a name (I used myBackColor) and then click OK. Notice that I didn't actually change the BackColor for the form. The purpose of this step is to simply create the app.config file. If you're watching carefully, you'll see it pop into existance in Solution Explorer. This is an XML file which now has a custom setting entry for BackColor. Leave the Scope setting set to User.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Step 4 - Now, we add the two lines of code that are necessary to take advantage of our application setting. In the Click event for the Button component, add this code:
ColorDialog1.ShowDialog()
My.Settings.MyBackColor = ColorDialog1.Color
That's all it takes! Visual Basic, in contrast to C# and other languages, saves the settings automatically when the form is closed.
To see Application Settings in action, start the application and click the button. Select any color from the color dialog and the background will change to that color. Then close the application. (You can close down VB.NET entirely if you want to be sure!) Restart the application and the backcolor will still be the same color that it was when you closed it! (Stopping the debug session won't save it however. You must close the form.)
There are more ways to create application settings. The next page tells you what they are!

