I've been away from my C# programming course now for months and am very rusty to say the least.

My assignment calls for the creation of a MDI text editor project. I am currently having trouble in coding such that the child form containing a rich text box is recognized from the main parent form.
I use an 'open' file strip menu item on the parent and plan to use a 'save' file strip menu item on the child form to save changes to the text. I use the openFileDialogue tool.

So far in coding the openToolStripMenuItem_Click event I have this:

private void openToolStripMenuItem_Click(object sender, EventArgs e)
   // Ask user to select a file to open.
   DialogResult responseDialogResult;
   // Begin in the project folder.
   openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory();
   // Display the file open dialog box.
   responseDialogResult = openFileDialog1.ShowDialog();
   if (responseDialogResult != DialogResult.cancel)
      // User did not cancel - select file.
      string fileString = openFileDialog1.Filename;
      // Open and read file.
      string fileText = File.ReadAllText(fileString);

      // Now I wish to display this text in richTextBox1 of the childForm.
      // IF the richTextBox was on this parent form this is how I would code it.
      richtextBox1.Text = fileText.ToString();
      // BUT of course richTextBox1 is on the childForm and is not recognized and
      // I don't know how to get it done in code.

I have done the IsMdiContainer property to 'true' on the parent form.

5 Years
Discussion Span
Last Post by samson_zed

Hi chellam

My suggestion would be

childform A;
// ---ur chld form name

// create instance in the open file dialog or during the Mdiparent load
A = new childform();
A.richtext1.text = fileText.ToString;

//Use A.show() to view and A.hide() to close



This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.