I have settings that are in the user scope and I can update them at runtime. When I call the save method,nothing gets saved. Any ideas
I have settings that are in the user scope and I can update them at runtime. When I call the save method,nothing gets saved. Any ideas
Properties.Settings.Default.Save(); does not save a user.config file.
gisgeezer
I gave up on doing that.. I'm not that smart.. I just made info in the registry and works OK!
Wondering why THAT should be so HARD!
Trevor2006
pqjr
hi,
will george its not that hard, here its how can you do it
1. Add the proper setting to you Settings.settings file
in your solution explorer expand properties node and double click Settings.settings file, use the UI to add your properties in my case i added 2
Name type scope Defaultvalue
Form1Location System.Drawing.Point user 10,10
Form1Size System.Drawing.Size user 250,250
then save the settings this will make 2 more nodes appear in your app.config
<
configSections><
sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" ><
section name="WindowsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /></
sectionGroup></
configSections><
userSettings><
WindowsApplication1.Properties.Settings><
setting name="Form1Location" serializeAs="String"><
value>10, 10</value></
setting><
setting name="Form1Size" serializeAs="String"><
value>250, 250</value></
setting></
WindowsApplication1.Properties.Settings></
userSettings>ok now how to use this in code
public partial class Form1 : Form {
public Form1()
{
InitializeComponent();
//Load saved settings this.Location = Properties.Settings.Default.Form1Location;
this.Size = Properties.Settings.Default.Form1Size;
//Allow changes to be implemented this.StartPosition = FormStartPosition.Manual;
//capture changes this.LocationChanged += new EventHandler(Form1_LocationChanged);
this.SizeChanged += new EventHandler(Form1_SizeChanged);
//capture the closing form event to save your new settings this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
}
void Form1_LocationChanged(object sender, EventArgs e)
{
//Capture the new values Properties.Settings.Default.Form1Location = this.Location;
}
void Form1_SizeChanged(object sender, EventArgs e)
{
//Capture the new values Properties.Settings.Default.Form1Size = this.Size;
}
void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
//you can capture the new values here as well //Properties.Settings.Default.Form1Location = this.Location; //Properties.Settings.Default.Form1Size = this.Size; //save the new values Properties.Settings.Default.Save();
}
}
this is a nice article on msdn about how to use settings http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnvs05/html/SettingsCS_RL.asp
plz note the app.config in your solution explorer and app.exe.config in yourProjectFolder\bin\debug will hold the default values , so don't expect you will find the chanes in those two files, but when the values changed in your app it will be saved where Rod Yager has said,
hope this helps
Ted.
double dou = OneWireLearning.Properties.Settings.Default.ccwLargeA;
OneWireLearning.Properties.Settings.Default.cwLargeA = 9.876543;
double dou2 = OneWireLearning.Properties.Settings.Default.cwLargeA;
OneWireLearning.Properties.Settings.Default.Save();
The value of cwLargeA is 9.876543 during runtime, but after closing the program and checking the settings file, it's back to it default value.
Anyone see the problem
Thanks
Ultrawhack
Jessie Zhao
This is working. Had to perform a Properties.Settings.Default.Upgrade() and then my saved settings get loaded.
I saw .. and then my saved settings get loaded.
I almost got loaded trying to solve this one! I still do not have it saved!
I'm not the sharpest Tack in the factory but if you hammer on me long enough (and I do not bend over) I can hold the fabric....
Anyway, seems so simple till' ya' try to do it! No matter what I try I still end up with the original settings when I restart the program. I guess my real question is in what order and when do you do your 'Properties.Settings.Default.Upgrade() ' and when do you do the save I'm so lost.. LOL... So bad here it is really funny!
I tried things like
Properties.Settings.Default.DCS900W_IP = textBox_WebCamAddress.Text;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Save();
(Many different orders) AND do a Properties.Settings.Default.Upgrade(); On initialize of the program.
All in all I end up with what I put into the 'Setting' in the first place.. Geeeeeeeeeee.. HELP!
RaviKanthReddy
In my case it is saving the settings in the App.Config file but I can't get it to load or save any settings. Here is what I have:
<userSettings>
<namespace.Properties.Settings>
<setting name="WindowLocation" serializeAs="String">
<value>0, 0</value>
</setting>
<setting name="WindowSize" serializeAs="String">
<value>363, 359</value>
</setting>
</namespace.Properties.Settings>
</userSettings>
Here is the code to load the preferences:
if
(Settings.Default.WindowLocation != null){
this.Location = Settings.Default.WindowLocation;
}
if (Settings.Default.WindowSize != null)
{
this.Size = Settings.Default.WindowSize;
}
Here is the code to save the preferences:
Settings.Default.WindowLocation = this.Location;
if (this.WindowState == FormWindowState.Normal)
{
Settings.Default.WindowSize = this.Size;
}
else
{
Settings.Default.WindowSize = this.RestoreBounds.Size;
}
Settings.Default.Save();
I have tried everything I can think of and I can't get this to work. Any help would be greatly appreciated.
David Day
Sundaraguru
lagu2653
EddieBear
Thanks
DanDMan
Thank You for the code. I'll give it a try.
Have a GREAT day..
YellowShell
Thank You for the information.
I learn something new everyday!
krishna mohan2990
[assembly:
AssemblyCompany("CompanyName")]