Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi everybody. I have a little problem.
I create two Form:

Form1 = main form MDIParent
Form2 = Child form

Form2 child Form member= textBox111
textBox111.Text= "" emtpy

I call to Form2 not any problem.

This code:
C#
Form2 frm =new Form2();
frm.MdiParent=this;
frm.Show();


My problem write random data textBox111.Text (e.g Welcomme) click button on Form1. Message box Welcomme not to appear.

This code:
C#
Form2 frm = new Form2();
string msg = frm.textBox111.Text;
MessageBox.Show(msg);


Empty message box to appear.

Sorry for bad English.

Thank you in advance for your help.
Posted
Comments
[no name] 21-Jul-15 13:41pm    
You create a brand new never before seen Form2 and get the text from an empty textbox. What else did you expect to happen?
Sergey Alexandrovich Kryukov 21-Jul-15 13:44pm    
This is the answer. Why not posting it as a solution?
—SA
EssenceGold 21-Jul-15 13:50pm    
My aim is to save all the data files in the TextBox on form2. But I can not access the data that I wrote out form1. Even if the data does not show, as I wrote in the above example.
[no name] 21-Jul-15 13:59pm    
You need to use the already existing instance of your form. Not create new instances that are empty.

 
Share this answer
 
Hi everybody. My problem solved. Below the code solves my problem. Thank you for your interest.

C#
public partial class Form1 : Form
 {

     Form2 frm;

     public Form1()
     {
         InitializeComponent();
     }

     private void toolStripButton2_Click(object sender, EventArgs e)
     {
         frm = new Form2();
         frm.MdiParent = this;
         frm.Show();
     }

     private void toolStripButton1_Click(object sender, EventArgs e)
     {
        MessageBox.Show(frm.textBox111.Text);
     }
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900