Application Settings
May 9th, 2007

How To Use Application Settings
In the past VB’ers have used INI files or the Registry to save application settings. This required either working within the narrow confines of the GetSetting function or writing API code to do the work. In VB.NET, we can use our application’s config file to save settings on a per user basis and we don’t even have to code a thing if we don’t want to.
Here are the steps you take to save values from bindable controls on your forms in Visual Studio 2005 without any coding.
1. In form design mode, select your text box and go to the Properties window’s Data section
2. Expand the (ApplicationSettings) line
3. Click on the … box on the (PropertyBinding) line below it.

4. You’ll get a dialog for Application Settings and it should default to the Text property.
5. Click on the dropdown that appears when you select the line

6. In the dropdown, click on the New link at the bottom. This will cause the New Application Setting dialog to appear
7. Enter the default value and name for your new setting.

8. Click OK on both dialogs to go back to the main Visual Studio screen
9. Now you’ll see your new Application Setting is bound to the text property of the textbox.
10. Repeat this process for your other controls.

11. In Solution Explorer, click on My Project.
12. Go to the Application Tab and make sure you have “Enable application framework” and “Save My.Settings on Shutdown” checked.

That’s all you need to do and everything will happen automatically when your application runs. The only time things won’t be saved would be in case of an abnormal shutdown due to a program exception or the program being terminated by Task Manager.
If you want to use code or if you having settings that can’t be bound, you can use the My namespace to work with your settings. It’s as easy as coding:
My.Settings.YourSettingNameHere = MyVariableHere
No more API calls, just a simple single line of code. How easy is that?
You could use this namespace to add your own static values as well. You can even use events in that part of the namespace to load settings from outside the application config if you want. You could save complex objects as serialized data to settings as well. I’ll be covering how to do this in other articles.
Entry Filed under: VB.NET Tutorials
Rate This Article:











Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed