You could mark the controls as internal or public (they're protected by default), which would allow you to access them from other forms in your application. This can lead to a relatively brittle design changes to the form's implementation can break other code. (i.e. Changing a textbox to a dropdown list changes the method of access the content.) I would prefer to see a solution such as a property or method on Form2 that would allow you to access this data. For instance:
class Form2 : Form { //... public string CompanyName { get { return tbCompanyName.Text; // If implementation or field name ever changes, then change it once right here. } } //... }
In Form1: form1.textBox1.Text = form2.CompanyName; |