Passing information between forms
I need to pass information between a form created from another form whats the best way to do this????
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Sep 4, 2007, 1:43 PM
The forms need references to each other to pass information.
If you're using .NET 2.0, the easiest way to get those references is to use the Application.OpenForms property which returns a FormCollection of every open form in the application.
If you have two forms, Form1 (the main form) and Form2, then this code will get the references you need:
Form1 form1 = (Form1)Application.OpenForms[0];
Form2 form2 = (Form2)Application.OpenForms[1];
So, if Form1 has a public TextBox (TextBox1 say) and you want to set the Text property from Form2, you can do:
form1.TextBox1.Text = "some text";