Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Creating, Using and Saving My.Settings Default Values in Visual Basic 2005
 »  Home  »  Visual Studio 2005  »  Creating, Using and Saving My.Settings Default Values in Visual Basic 2005
Creating, Using and Saving My.Settings Default Values in Visual Basic 2005
by Dave Barr | Published  05/29/2006 | .NET Newbie Visual Studio 2005 | Rating:
Dave Barr
Not much to tell, so for now view some of my custom logo designs, and a photograph of mine that made it to the local newspaper. 

View all articles by Dave Barr...
Getting Started

This is a short and very basic tutorial about creating, using and saving My.Settings default values in Visual Basic 2005. By completing this tutorial you will learn the basic steps involved in creating Settings that can be saved and re-loaded the next time your application is run.

Open Visual Studio 2005, create a new project and name it: VbCity Sample Project

 

Press the "Project" menu item, then press the "VbCity Sample Project Properties..." sub-menu. The VbCity Sample Project Properties Window will open. Press the "Settings" Tab located near the center left of the window.

 

The Settings Window is where you add variables/constants that can be used anywhere throughout the entire project. If you take a peek at the options listed in the 'Scope' ComboBox, you will see a choice of 'User' or 'Application'. Application Scope is used as a constant, which means the value you add in design-view cannot be changed during runtime.

A good example of Application Scope is a database connection string. Normally, a connection string is set by the programmer and isn't changed by the user.

User Scope is used as a variable, which means you can change its value during runtime. Another great advantage of a User Scope variable is that you can save the value to reuse next time the application is run. All of the examples in this tutorial will use the User Scope.

Comments    Submit Comment

Comment #1  (Posted by an unknown user on 06/01/2006)
Rating
Very clear to follow. All actions mentioned.
 
Comment #2  (Posted by an unknown user on 06/13/2006)
Rating
Thanksssssssssssssssssssssssss so much

vbapr@yahoo.com
 
Comment #3  (Posted by Mark on 06/23/2006)
Rating
What about writing an reading the settings programmatically?Can we do that?any examples would be fantastic
 
Comment #4  (Posted by an unknown user on 06/23/2006)
Rating
What about reading pages 3 and 4 where it's explained?

Page 3:
Me.BackColor = My.Settings.DefaultFormColor
Me.TextBox1.Font = My.Settings.DefaultFont
Me.TextBox1.ForeColor = My.Settings.DefaultFontColor
Me.TextBox1.Text = My.Settings.DefaultName

Page 4:
My.Settings.DefaultName = Me.TextBox1.Text
 
Comment #5  (Posted by an unknown user on 07/01/2006)
Rating
Thank You! Great and Simple.
 
Comment #6  (Posted by an unknown user on 07/02/2006)
Rating
Great!
 
Comment #7  (Posted by an unknown user on 07/03/2006)
Rating
Easy to follow, thank you.
 
Comment #8  (Posted by an unknown user on 09/01/2006)
Rating
Thanks Alot;;There is no way to change app level settings during setup/runtime ?
 
Comment #9  (Posted by an unknown user on 09/01/2006)
Rating
DAVE PASSED AWAY ON JULY 31, 2006.
 
Comment #10  (Posted by an unknown user on 10/05/2006)
Rating
My condolences, looks like a great guy. Great tutorial as well.
 
Comment #11  (Posted by an unknown user on 10/21/2006)
Rating
Thank you very much!

Johannes
 
Comment #12  (Posted by an unknown user on 11/07/2006)
Rating
The best and easiest way to save app settings! Thanks!!:D

//Fredrik Ragnarsson
SWEDEN
frrag001@hotmail.com
 
Comment #13  (Posted by an unknown user on 12/06/2006)
Rating
just a perfect example...
 
Comment #14  (Posted by an unknown user on 04/18/2007)
Rating
It really solve my problems with new Settings of VS2005!!!
 
Comment #15  (Posted by an unknown user on 05/09/2007)
Rating
Short and Clear. ThanX
Ralph
 
Comment #16  (Posted by Chris Walker on 07/12/2007)
Rating
The new way to do this in VS 2005 is to use PropertyBinding. It does the same thing, but without any code.

Add a control to a form, view the properties of that control, go to ApplicationSettings, there you will see PropertyBinding. Opent that up, pick a property, give it a new name to save the settings to, and viola, you are done.
 
Sponsored Links