Support Forums

Full Version: [Vb.Net]Save user settings with "My.Settings"[TUT]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is a really useful way to save the users settings in your apps. Ive seen other ways which are good but this works for me.

1. Create a New project call it whatever you want, I named mine "MySettings".

2.Add a Textbox and Button control to your app.
The buttons text should read "Save".
On the textbox, I set to multiline.

[Image: form.png]

3. Click on My Project in the soultion explorer
4. Click the Settings Tab
5. Add a new "Name" for your setting, this name will be used kinda like a variable. I named mine textsaved.
6. Under the "Type" column click "String" I actually think this is by default. Now you could use the other Data types as well, depending on what your really trying to save.
7. Under scope you want "User" scope cause its the user saving not the "Application".
8. Optional: depending on the setting, for "value" it would be a text value since where using a string type. But for now just leave it blank cause where going to fill that up with user input.

[Image: myprojects.png]

Heres the code where going to use:

[Image: codev.png]

So starting typing some non-sense in the textbox.
Then click the save button and close the app.
Reopen the app and bam your text appears. Try it without clicking the save button and you get nothing.

Basicly in the button click event we are going to save the text in the textbox. Where not really saving the data yet just assigning it to the setting we made.

In the form closing we are actually saving. If you forget this line it will not save.

On the form load we are telling the textbox that its contents will be what was saved from the setting.

Well thats all there is to it. Hope this helps someone here.
I honestly know all this, but this is really good.
A really useful thread if I might say.
Thanks.
I mainly use this to save settings for like font colors,fonts and background colors for applications. Thanks for the feedback though.
Yes It's Really Useful.But It's Stores The All Settings In The File Settings.xml Which we can easily see using notpad.so It's Became useless when we want to make some application that stores secret string like password or licence key etc.
(10-14-2011, 01:07 AM)CodingWorm Wrote: [ -> ]Yes It's Really Useful.But It's Stores The All Settings In The File Settings.xml Which we can easily see using notpad.so It's Became useless when we want to make some application that stores secret string like password or licence key etc.

You would probably want to save a password to the registry correct?
Yeah You are Right.In Registry with encryption.
looks very interesting thanku for this im trying to learn
You can still save the setting as an encrypted hash and just decrypt it. Also, for future reference using the ApplicationSettings > PropertyBinding, you can auto-save settings so you don't have to call them up in the Form_Load...

[Image: bb308902.vb-5-8(en-us).gif]

Most properties work, but I did notice for the NumericUpDown's you need to save the setting (My.Settings.Save()) in the ValueChanged event. Hope this helps someone, great shortcut ;)