Search code examples
c#winformstextboxpersist

Winforms/C#: Store/Retrieve (Persist) Content of TextBoxes between 2 Runs


Is there an easiest way to simply tell Winforms (mainly TextBoxes) to persist all its content e. g. to a file without me having to loop through all the controls?

I saw this in a WPF application, but am clueless (also, Google did not turn up anything) whether there is an out-of-the-box, easiest approach.

Again, looping through each control would be possible but seems.. too much work?

Would serialization maybe work?


Solution

  • You can set your ApplicationSettings PropertyBinding in the Form Designer, assign it a Field Name then when you close your application you can do this which will save all of you changes to all of the bound textbox's in the applications app.config file.

    enter image description here

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        Properties.Settings.Default.Save(); 
    }