darksageaura 0 Newbie Poster

Hi,

I've just started using Visual C# express, and honestly I like it. I'm running into the same problem I had when I first started Visual Basic, Its the saving multiple text boxes and some of them are multi lines so when you press enter in the multi line box it will goto the next line.

I was wondering what would be a better way of saving and reading these text boxes, I'll give my current coding.

This is my saving coding:

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog1.Filter= "Text File (*.txt)| *.txt";
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFileDialog1.FileName);
                sw.WriteLine(textBox1.Text);
                sw.WriteLine(textBox2.Text);
                sw.WriteLine(textBox3.Text);
                sw.WriteLine(textBox4.Text);
                sw.WriteLine(textBox5.Text);
                sw.WriteLine(textBox6.Text);
                sw.WriteLine(textBox7.Text);
                sw.WriteLine(textBox8.Text); <----- multi line box, so pressing enter in this box will put it to the next box when opening.

Here is my opening coding:

private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            openFileDialog1.Filter = "Text Files (*.txt)| *.txt";
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName);
                textBox1.Text = sr.ReadLine();
                textBox2.Text = sr.ReadLine();
                textBox3.Text = sr.ReadLine();
                textBox4.Text = sr.ReadLine();
                textBox5.Text = sr.ReadLine();
                textBox6.Text = sr.ReadLine();
                textBox7.Text = sr.ReadLine();
                textBox8.Text = sr.ReadLine();

Any help in streamlining this and input will be helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.