tags:

views:

399

answers:

1

I have 4 textboxes and I have to write what's contained in there to a textfile I'll randomly generate. How will I write textbox data to the text file? and exactly where in the code? If i do it in :

private void textBox1_TextChanged(object sender, EventArgs e)

and have it all in the boxes textchanged parts, I can only get one textbox written.

Also how will I generate a txt file, that I'll randomly name with a 5 lettered name?

+2  A: 
StreamWriter writeFile = new StreamWriter(fileLocation);
writeFile.WriteLine(textBox1.Text);
writeFile.WriteLine(textBox2.Text);
//etc.

writeFile.Close();

It depends what your aim is, as to when to save the file. If you want to save every time a text box text is changed, hook them all up to that event.

Althought if otherwise you could do it on a button click (save button?).

You will need to give more details for a more appropriate answer.

ThePower
How do i bind this to a button click?
Lady Sour
The same as you did with the TextChanged event for the TextBox. Add a button to your form, then either double click the Click event in the Events or in code assign it as yourButton.Click += new EventHandler(yourButton_click);
ThePower
thank you so much, I've done it =)
Lady Sour