In order for a form change to be noticed by the MainForm, it must offer interfaces.
It is not easy for beginners to see the connections.
Here is an example that illustrates how, for example, a text that you enter in the main form in a TextBox can be transferred to another form:
First we instantiate the SubForm Global in the MainForm and display it in the MainForm load event:
Form 1 Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public partial class Form1 : Form { Form2 form2 = new Form2(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { form2.Show(); } } |
Then we insert a public method in the subform that outputs a MessageBox with passed parameters.
Form 2 Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public partial class Form2 : Form { public Form2() { InitializeComponent(); } public void DoMessageBox(string messageBoxText) { MessageBox.Show(messageBoxText); } } |
TextChanged Event
1 2 3 4 5 6 | private void textBox1_TextChanged(object sender, EventArgs e) { form2.DoMessageBox(textBox1.Text); } |
Now, You can see how the subform outputs a MessageBox with passed TextBox content.