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();
VulpesPosted May 23, 2014, 12:13 PM
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);
B RawlingsPosted May 24, 2014, 2:36 PM
B RawlingsPosted May 23, 2014, 11:20 AM
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?
VulpesPosted May 20, 2014, 7:07 PM