Saving User and Application Settings in WinForms
-
I want to save changes in my C# form. So I tried this. There are 3 buttons on my form but the code saves only button3's location. What should I do? Please help me!
foreach (Button a in Form1.ActiveForm.Controls) { Properties.Settings.Default.SavedSetting3 = a.Location; } Properties.Settings.Default.Save();
Thanks in advance
-
I want to save changes in my C# form. So I tried this. There are 3 buttons on my form but the code saves only button3's location. What should I do? Please help me!
foreach (Button a in Form1.ActiveForm.Controls) { Properties.Settings.Default.SavedSetting3 = a.Location; } Properties.Settings.Default.Save();
Thanks in advance
You can save in one setting entry only one value. From what you are doing, you are trying to save 3 different locations to one setting entry(SavedSetting3) which is wrong. In each loop execution you are overwriting the last set value and hence, the value which is last written (button3 I guess) is the one which is saved. You will need to create 3 different setting's entry to save each of the buttons location.
-
You can save in one setting entry only one value. From what you are doing, you are trying to save 3 different locations to one setting entry(SavedSetting3) which is wrong. In each loop execution you are overwriting the last set value and hence, the value which is last written (button3 I guess) is the one which is saved. You will need to create 3 different setting's entry to save each of the buttons location.
-
I want to save changes in my C# form. So I tried this. There are 3 buttons on my form but the code saves only button3's location. What should I do? Please help me!
foreach (Button a in Form1.ActiveForm.Controls) { Properties.Settings.Default.SavedSetting3 = a.Location; } Properties.Settings.Default.Save();
Thanks in advance
You can have these settings saved for you automatically. Just have a google for 'App.Config' or 'Saving Form Location' and read up about it.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”