hi,
i want to know what's the difference between those 2 ways in saving variables and which one is better or what's the use of each one
1) MyControl.Property = global::MyApp.Properties.Settings.SettingName;
i saw the designer use this way can i use this way to save my variables like for example userName and password when the user check remember me check box
2) string user = ConfigurationSettings.AppSettings["UserName"];
this method give me warrning " i should use ConfigurationManager , but when i type ConfigurationManager it give me errors as if no class so called like that, also when i try to add NameValue Pair the compiler complain and say this is read only are those bugs one more thing the previous way store the value in App.Config but i don't know where this way store its values
Q: so if i used any of those 2 ways can the value be global value , which i change it from one form and call it from another form if i needed to
the sad part is that neither way worked for me
//ConfigurationSettings.AppSettings.Add("something", "value"); string x = ConfigurationSettings.AppSettings["something"]; x = "one"; MessageBox.Show(x); //this line gives error no data in the collection MessageBox.Show(ConfigurationSettings.AppSettings.Get(0)); string y = global::MyAPP.Properties.Settings.Default.varName; y = "two"; MessageBox.Show(y); //this line show the default value even after i changed the value MessageBox.Show(MyAPP.Properties.Settings.Default.varName); |
thx in advance

Application settings
Mutt10R
hi,
i found this article has the same solution as what battula describe but with further explanation
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnvs05/html/SettingsCS_RL.asp
thank you
Pedro J. Molina
hi,
thx Christian but neither way worked for me, but i want to add an example for what i want to do here, do you know when you change a form location and size next time you run this program you will find the settings the same as last time you used this program, by other word not to make your application forgetfull
something like databindings when you run you application you will read values if you changed it you save it in few steps
i wan't to do the same thing on my project and also some varaibles in my app, i can use registery or i can do that by using extra file but i want to use settings, and to save it all in one or two steps , because if i want to save each variable indvidualy it will be a miss , just try to imagine if you save your dataset row by row without iteration,
so how can i do something like this , i'm very confused here any clarification will be appreciated
best regards
David_Som
This also nice idea of saving our persistance items using Properties.Settings. After defining the items here we need to call this in our form code.
like
this.location = WindowApplication.Properties.Settings.Default.Setting.
the value of setting give some values (Ex:100,100)- This is windows default position.
Here i am eqating this to Form location so Setting datatype should be System.Drawing.Position
Move window and close.
in from closing event write this code
Properties.
Settings.Default.winPos = this.Location;WindowApplication.Properties.
Settings.Default.Save();if u start exe again then u will get most ressent windows position.
These values will store in "C:\Documents and Settings\<UserName>\Application Data\Current Application Name.exe_Url_5cwhv0cpmpdff4bregwd04ousnhsq3md" some thing like this folder u can see
I this based on Application version, One more version folder will create. In that version folder "user.config" file we can see. All defined persistence values will be stored in this file. If u change the path of Exe file one more Application name with some differnt script folder will from.
If u remove this folder and run exe, the default position( defalut values defined in Poperties.Setting file) will appear.
Mattias Sjogren
From memory, the 2.0 configuration manager requires you to add a reference to your project. That threw me when I did an upgrade on a project, and that was the solution. I don't believe the configuration manager can save settings, unless that is new in 2.0.
If a value is stored in your config, it's global by definition, you can access it anywhere.
DenverCoder