I am trying to add the contents of a text file to a text box in a child form using 'Open' from the parent file. This is what I have so far:
{
openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory();
// Display the file open dialog box and show only text files.
DialogResult responseDialogResult;
openFileDialog1.Filter = "Text Files (*.txt)|*.txt";
responseDialogResult = openFileDialog1.ShowDialog();
// Check that the user did not click the cancel button.
if (responseDialogResult != DialogResult.Cancel)
{
// Open the child form.
Form2 childOneForm = new Form2();
childOneForm.MdiParent = this;
childOneCountInteger++;
childOneForm.Text = openFileDialog1.FileName;
childOneForm.Show();

VulpesRank #55 · 29.2K reputationPosted May 23, 2014, 8:13 AM EDT
To write it to a textbox first change the textbox's Modifiers property (in the Properties Box) from private to internal so it can be directly accessed from other forms in the same program.
Now replace this line:
childOneForm.Text = System.IO.File.ReadAllText(openFileDialog1.FileName);
with this one (use the actual name of the textbox if it's not textBox1):
childOneForm.textBox1.Text = System.IO.File.ReadAllText(openFileDialog1.FileName);
VulpesRank #55 · 29.2K reputationPosted May 20, 2014, 3:07 PM EDT
B Rawlings6 reputationPosted May 23, 2014, 7:20 AM EDT
Thanks for your replay but I am still not able to get the contents of the text file to show in the textbox
Any idea?
B Rawlings6 reputationPosted May 24, 2014, 10:36 AM EDT