Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Application Settings in VB 2005  »  Create Settings
 »  Home  »  Windows Development  »  Visual Basic 2005  »  Application Settings in VB 2005  »  Create Settings
 »  Home  »  Windows Development  »  Win Forms  »  Application Settings in VB 2005  »  Create Settings
Application Settings in VB 2005
by Ged Mead | Published  11/09/2006 | .NET Newbie Visual Basic 2005 Win Forms | Rating:
Create Settings

Demonstration Settings

   As a demonstration task, we will add three new Settings. 

   The first will store a user's chosen user name, the second will save the user's choice of form color and the third will optionally allow the user to save the size of the form as the user's chosen values.

User Name

   Click on the first line of the Settings Grid and double click on the first item in the Name Column (which by default is named "Setting") to highlight it.  Now overtype "Setting" with "UserName".

   Leave the Type column item at the default of "String" and the Scope at the default of "User".

   All that remains is to add a default value for this string.  Type in the word "Anonymous".

   The screenshot below shows these steps completed:

   You might notice that the Settings are also displayed in a standard Visual Studio Properties Window at the bottom right of the IDE.   Settings can be edited in the normal way here as well as in the Settings grid.

Form BackColor

   To demonstrate saving a Setting of a different Type, the next line will be used to enter the details of the Form's BackColor.   The screenshot below shows the Settings used.  You simply click on the down arrow to the right of the Type and select System.Drawing.Color from the drop down list. 

  Click anywhere inside the Value cell and a small down arrow will appear.  Click this in order to view the standard three-tab color choices list.  

Form Size

   Finally, add a third Setting named FormSize, select the System.Drawing.Size Type from the dropdown list and type in your chosen values for width and height in the Value cell. 

   I have purposely made the form size quite small so as to encourage the user to change it and then save it.

 

 

  

Comments    Submit Comment

Comment #1  (Posted by TobyT on 11/09/2006)
Rating
Good for beginners.
 
Comment #2  (Posted by an unknown user on 12/05/2006)
Rating
Usefull feature i've never heard about before, nice article.
 
Comment #3  (Posted by an unknown user on 12/16/2006)
Rating
It is good for beginners & and to those that are not familiar with VB 2005.
 
Comment #4  (Posted by Michael Ifland on 02/11/2007)
Rating
Thank You.
 
Comment #5  (Posted by Majed on 02/21/2007)
Rating
Still too many details are missing.
 
Comment #6  (Posted by an unknown user on 08/18/2007)
Rating
Ged's articles just keep getting better and better. Being a complete newbie I really appreciate the in depth explanation of details that I am sure are common knowledge to others.
 
Comment #7  (Posted by an unknown user on 10/19/2007)
Rating
Good beginner article
 
Comment #8  (Posted by Noname on 01/04/2008)
Rating
One big mistake:

In page 2, the formsize is set without ";" (semicolon) between size values which gives error. Developers must add ; to overcome error.
 
Comment #9  (Posted by Ged Mead on 01/05/2008)
Rating
Hi "NoName". Thanks for pointing out this problem. I suspect that in truth, this may not be so much a big mistake as a fairly common locaization/internationalisation issue which occurs in many prjects where dates, times and numbers etc are used. This is because in many Western cultures, such as here in UK, we use commas, whereas elsewhere semicolons are used as delimiters.
All I can say for sure is that the sample works perfectly on my English UK system. I'm sorry if it has caused you problems.
 
Comment #10  (Posted by i.write.code on 01/22/2008)
Rating
Perfect! Thanks for pointing out the Save and Reset methods. I was pulling out my hair over settings that always seemed to reset on their own when my application was restarted.
 
Comment #11  (Posted by Rob 73 on 05/02/2008)
Rating
Just want to say thank your for a very clear, easy to follow and extremely useful article. I was initially reluctant to try using the 'my.settings' as i 'thought' it was difficult and complex when saving user preferences, and as a result nearly tore all my hair out trying to read and write from/to text files.
Thanks from me and my 'Not so bald head'
Keep up the good work!


 
Sponsored Links