Joseph Longo
asked on
C# passing a file name to a child window
I need to open the file that i selected in the parent window.. in the child window.
my plan is to pass the child form the filename and then open it and display it in the child form.
How do i pass the filename to the child window?
i have attached source.
Form1.cs
FormChild.cs
my plan is to pass the child form the filename and then open it and display it in the child form.
How do i pass the filename to the child window?
i have attached source.
Form1.cs
FormChild.cs
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when i use the fc.Text command it uses "hello" in the title bar of the new child window.
how do i get that value into the body of the child window?
private void openToolStripMenuItem_Clic k_1(object sender, EventArgs e)
{
OpenFileDialog ofdOpenFile = new OpenFileDialog();
ofdOpenFile.Title = "Select a File To Open";
ofdOpenFile.FileName = "";
ofdOpenFile.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (ofdOpenFile.ShowDialog() == DialogResult.OK)
{
RichTextBox rtb = GetRichTextBox();
if (rtb == null)
{
FormChild fc = new FormChild();
fc.MdiParent = this;
fc.Show();
string str = "hello";
fc.Text = str;
//str = fc.Text;
Application.DoEvents();
}
if (rtb != null)
{
rtb.LoadFile(ofdOpenFile.F ileName, RichTextBoxStreamType.Rich Text);
}
}
}
how do i get that value into the body of the child window?
private void openToolStripMenuItem_Clic
{
OpenFileDialog ofdOpenFile = new OpenFileDialog();
ofdOpenFile.Title = "Select a File To Open";
ofdOpenFile.FileName = "";
ofdOpenFile.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (ofdOpenFile.ShowDialog() == DialogResult.OK)
{
RichTextBox rtb = GetRichTextBox();
if (rtb == null)
{
FormChild fc = new FormChild();
fc.MdiParent = this;
fc.Show();
string str = "hello";
fc.Text = str;
//str = fc.Text;
Application.DoEvents();
}
if (rtb != null)
{
rtb.LoadFile(ofdOpenFile.F
}
}
}
ASKER
this was solved like this.
in the child form add an argument for passed filename and load into rechtextbox:
public FormChild(string fileName)
{
InitializeComponent();
richTextBox1.LoadFile(file Name, RichTextBoxStreamType.Plai nText);
}
in the parent form pass the name:
FormChild fc = new FormChild(ofdOpenFile.File Name);
fc.MdiParent = this;
fc.Show();
in the child form add an argument for passed filename and load into rechtextbox:
public FormChild(string fileName)
{
InitializeComponent();
richTextBox1.LoadFile(file
}
in the parent form pass the name:
FormChild fc = new FormChild(ofdOpenFile.File
fc.MdiParent = this;
fc.Show();
ASKER
it was the solution that i worked out.
ASKER
i cant even get the parent window to show files contents.
how do i get the string text contents into the parent window?
at least i can start here...
see this code:
private void openToolStripMenuItem_Clic
{
OpenFileDialog ofdOpenFile = new OpenFileDialog();
ofdOpenFile.Title = "Select a File To Open";
ofdOpenFile.FileName = "";
ofdOpenFile.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (ofdOpenFile.ShowDialog() == DialogResult.OK)
{
string file = ofdOpenFile.FileName;
string text = File.ReadAllText(file);
//RichTextBox rtb = GetRichTextBox();
FormChild fc = new FormChild();
fc.MdiParent = this;
fc.Show();
Application.DoEvents();
}
}