0

Have this code in place:

private void button32_Click(object sender, EventArgs e)
{
    string Current = textBox23.Text;
    label60.Text = Current;
    int SaveRate = Convert.ToInt32(Current);
    SaveRate = Properties.Settings.Default.PriorExclTimer;
    Properties.Settings.Default.Save();
}

Code updates the label fine, but it doesn't update App.config and save the new setting. The setting type is PriorExclTimer, and it is stored as int. Not sure what I need to do to add the value and save it to the App.config xml.

One unintended thing happens with this code. When the program opens using Start, somehow the label remembers the last number typed in textBox23, even though the xml is not changing when the button is pressed (xml contains a different value than what shows in label60 on Start unless the last number used from the textBox was the same one as what is in the xml).

Some info. In the form.cs, I have added some code below the initialization statement that converts the int in App.config to string, so it can be added to the label (label 60) when the program starts. I was intending to use this methodology for several label controls. Here is all of the opening form.cs:

public HyperFlexTest()                
{
    InitializeComponent();
    Load += new EventHandler(HyperFlexTest_Load);
    int ExclRate = Properties.Settings.Default.PriorExclTimer;
    label60.Text = ExclRate.ToString();
}

Could this be affecting the later control code? Very curious about what causes the last number typed in textBox23 to persist, even past a restart of VS 2015 and even though the number doesn't match the number in the xml file.

I would also like to null the textBox (textBox23) value when the button is pressed.

Thanks

EDIT: The referenced thread question mentioned as a possible duplicate concerns the location of the settings file. My question is about about code context and changing the contents of the app.config file using a button...

Bo McCullough
  • 13
  • 2
  • 2
  • 6
  • 1
    You should revert the assignment _Properties.Settings.Default.PriorExclTimer = SaveRate;_ – Steve Nov 12 '16 at 15:07
  • Thanks. Same result. Opening value still appears to persist in the listbox and value doesn't update in app.config. I think I may have actually tried this once, but I tried a number of things, so I can't recall :(... – Bo McCullough Nov 12 '16 at 15:14
  • Possible duplicate of [Properties.Settings.Default.Save(); -> Where is that file](http://stackoverflow.com/questions/5789252/properties-settings-default-save-where-is-that-file) – derloopkat Nov 12 '16 at 15:24
  • OK. I have, previous to adding the above code, used some code to create a folder and settings file that is not app.config. It's still there and the settings.cs also. However, I didn't configure the dialog for any use. Could this be the problem? If so, can I safely just remove the code and delete from within VS the settings.cs. My intention was to use app.config to develop the program and then move it over to a /Roaming based xml in a later version. I don't need the folder and xml in /Roaming for now. – Bo McCullough Nov 12 '16 at 15:34

0 Answers0