Why Option Strict?

Application Settings

May 9th, 2007

Application settings are easy to use

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.

Application Setttings Example Steps 1-3

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

Application Settings Steps 4-5

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.

Application Settings Steps 6-7

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.

Application Settings Steps 8-10

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.

Application Settings Steps 11-12

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.

Share This Article: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Technorati
  • DotNetKicks
  • DZone

Entry Filed under: VB.NET Tutorials


Rate This Article:

Not That GoodCould Be BetterOKGoodGreat (No Ratings Yet)
Loading ... Loading ...

Leave a Comment

Required

Required, hidden

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


Most Popular Articles

Highest Rated Articles

Categories

Most Recent Articles

Feeds

 Subscribe in a reader

To subscribe by e-mail
Enter your address here

Delivered by FeedBurner

VB Opportunities

Archives