Click here to Skip to main content
12,817,956 members (37,355 online)

MDI forms Read from text and save to text

leetank asked:

Open original thread
Hello all I got a problem I am trying to open file and read the text to a form ok I open file I enter the text in rich textbox and I hit save now when I open the file again it blank ? this is the problem its not saving the text input so when I open a file in a Frmchild it should display the text.
<pre lang="c#">

  public partial class frmChild2 : Form
        public frmChild2()
    public frmChild2 ( string fileName )
    : this()

    private void Savefile ( string fileName )

    string strExt;
    strExt = System.IO.Path.GetExtension(fileName);
    strExt = strExt.ToUpper();
    if (strExt == ".RTF")

    richTextBox1.LoadFile(fileName, RichTextBoxStreamType.RichText);

    System.IO.StreamReader txtReader;
    txtReader = new
    richTextBox1.Text = txtReader.ReadToEnd();
    txtReader = null;
    richTextBox1.SelectionStart = 0;
    richTextBox1.SelectionLength = 30;
    richTextBox1.Modified = true;
    this.Text = "Unit  9  Editor: " + fileName;

    private void btnSave_Click(object sender, EventArgs e)
                  SaveFileDialog savefileDialog = new  SaveFileDialog();
            savefileDialog.DefaultExt = "txt";
            savefileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            savefileDialog.Filter = "Text Files (*.txt)|*.txt|Html Files (*.htm)|*.htm|Rich Text Files (*.rtf)|*.rtf|All Files (*.*)|*.*";
            savefileDialog.FilterIndex = 1;
            savefileDialog.FileName = string.Empty;
            if (savefileDialog.ShowDialog(this) == DialogResult.OK && savefileDialog.FileName != String.Empty)

                Form frmChild = new frmChild2 (savefileDialog.FileName);
                frmChild = this;

                MessageBox.Show("Save File request cancelled by user.", "Cancelled");

Tags: C# (C#4.0)


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100