Article Options
Premium Sponsor
Premium Sponsor

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:
Add controls to the form

That's all the settings we need for this tutorial so save your changes. Close the Settings Window and set focus back to the Form1 Designer Window.

Add a TextBox to the form and stretch it almost the entire width of the form. Now select the form itself and double-click to open the code window for the Form1_Load event. Type the following code inside the Form1_Load event:

 

Me.BackColor = My.Settings.DefaultFormColor

Me.TextBox1.Font = My.Settings.DefaultFont

Me.TextBox1.ForeColor = My.Settings.DefaultFontColor

Me.TextBox1.Text = My.Settings.DefaultName

 

Press F5 to see your progress in action. You should have a form that looks similar to the following image:

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