I have two forms, on my first form I have a button to open up a Txt file, I have a second form that only has a textbox on it, currently I am able to open the second form onto my first form, but can't display the text onto form 2.
Currently I am using OpenFileDialog to choose txt file, but I'm unsure as to how to pass the txt file onto my second form.
For my first form called form1 I have the following code on my button meant to open a txt file.
private void smTxtOpen_Click(object sender, EventArgs e)
{
OpenFileDialog openText = new OpenFileDialog();
openText.InitialDirectory = @"C:\";
openText.Filter = "TXT Files(*.txt;)|*.txt;";
if(openText.ShowDialog() == DialogResult.OK)
{
using(StreamReader rdText = new StreamReader(openText.FileName))
{
Form2 newText = new Form2();
newText.MdiParent = this;
newText.Show();
}
}
}
On my second form I only have this code where I have tried to gather and return the txt file (my textbox is located on this form)
public TextDocumentForm()
{
InitializeComponent();
}
public string TextFileName { get { return tbText.Text; } }
At the moment I am able to successfully have my second form appear on my first form, but no text from my openFileDialog is displayed (since I wasn't able to figure out how to tie the two together.).
I'm not really sure how to proceed, being relatively new with c# I would appreciate any help.