[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# passing a file name to a child window

Posted on 2013-06-17
9
Medium Priority
?
393 Views
Last Modified: 2013-06-19
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
0
Comment
Question by:NJJoeG8GT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 450 total points
ID: 39253405
You can create a void SetFilename function in child form passing one string parameter. Then, from parent form, you can call that function in ActiveMdiChild.

Hope that helps.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 480 total points
ID: 39253448
0
 
LVL 15

Assisted Solution

by:Minh Võ Công
Minh Võ Công earned 570 total points
ID: 39253511
Form1:

publicpartialclass Form1 : Form
  {
    privateint _aSDJK = 27894;

    internalint asdfjkld
    {
      get { return _aSDJK; }
      set { _aSDJK = value; }
    }

    public Form1()
    {
      InitializeComponent();
      this.IsMdiContainer = true;
    }

    privatevoid Form1_Load(object sender, EventArgs e)
    {
      Form2 f = new Form2();
      f.MdiParent = this;
      f.Show();
    }
  }
Form2:

publicpartialclass Form2 : Form
  {
    public Form2()
    {
      InitializeComponent();
    }

    privatevoid Form2_Load(object sender, EventArgs e)
    {
      Form1 f = (Form1)this.MdiParent;
      MessageBox.Show(f.asdfjkld.ToString());
      f.asdfjkld++;
      MessageBox.Show(f.asdfjkld.ToString());
    }
  }
http://go4answers.webhost4life.com/Example/does-child-form-access-mdi-parents-136821.aspx
http://www.c-sharpcorner.com/forums/thread/124580/getting-variable-value-from-
mdiparent-form-to-child-form.aspx
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:NJJoeG8GT
ID: 39255114
ok.  thanks for all replies.  I am still struggling with this.
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_Click_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)
            {
                string file = ofdOpenFile.FileName;
                string text = File.ReadAllText(file);

               
                //RichTextBox rtb = GetRichTextBox();
               
             
                    FormChild fc = new FormChild();
                    fc.MdiParent = this;
                    fc.Show();
                    Application.DoEvents();

                 
               

             
            }
        }
0
 
LVL 15

Assisted Solution

by:Minh Võ Công
Minh Võ Công earned 570 total points
ID: 39255132
FormChild has a richtextbox control? You can public the control

in FormChile
public RichTextBox  m_rtb;
in Parrent
  FormChild fc = new FormChild();
  fc.MdiParent = this;
  fc.Show();
  string str ="hello";
fc.m_rtb.Text = str;
str = fc.m_rtb.Text;

and so on ...
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 480 total points
ID: 39255145
You can public the control
That's not a good suggestion. Making the RTB public means you are making every property the RTB exposes publicly available to any bit of code that has access to the RTB. Now code external to your form can do:

rtb.FindForm().Controls.Remove(rtb);

Open in new window


That seems like an awful amount of power to give up just for the sake of setting the RTBs text value. Expose a new property that grants access to just the RTB's Text property.
0
 

Author Comment

by:NJJoeG8GT
ID: 39257827
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_Click_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.FileName, RichTextBoxStreamType.RichText);
                }
            }
        }
0
 

Author Comment

by:NJJoeG8GT
ID: 39259299
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(fileName, RichTextBoxStreamType.PlainText);
           
        }
in the parent form pass the name:
                FormChild fc = new FormChild(ofdOpenFile.FileName);
                fc.MdiParent = this;
                fc.Show();
0
 

Author Closing Comment

by:NJJoeG8GT
ID: 39259337
it was the solution that i worked out.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question