I use this code for this:

void Form1_FormClosed ( object sender, FormClosedEventArgs e ) { StreamWriter sw = new StreamWriter("test.txt"); sw.WriteLine(textBox1.Text); sw.Close(); } 

All would be nothing, duck form now does not want to close. How to treat?

The most amazing thing is that if the file does not exist, then it is created (and this is correct, I need to) and the form closes normally. But if the file already exists, the form does not close.

    1 answer 1

    Or maybe we should change the event to Form_Closing? After all, you need to save data to a file: "when closing a form?" And not when the form is already closed ...

    • No, and with Form_Closing the same. - Smash
    • Hmm, strange for me, everything is fine; it keeps private void ; }} And everything closes normally. - Angus123 pm
    • one
      And, I found the reason, I wrote it here for an example, I wrote test.txt, and actually saved it in the file settings.ini, apparently the application somehow blocks this particular file, i.e. he is already busy - Smash
    • even it turned out that when I start the application, this file opens, and then I just forgot to close it. StreamReadeMyFile.Close () needed to be added. - Smash
    • I'm glad that everything works for you :) - Angus123