Passing information between forms
I need to pass information between a form created from another form whats the best way to do this????
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Sep 4, 2007, 9:43 AM EDT
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";