1. Create a class whose properties are the data elements that FormA is displaying and that FormB will be modifying.
2. Create an overload of Show() or ShowDialog() in FormB that accepts an instance of the class as an argument.
3. Make the class instance a private property of FormB.
4. Have FormB's Close() event handler update the class instance with the form's values.
Thus, FormA's button to open FormB has a Click handler like this:
MyClass foo = new MyClass();
foo.field1 = field1TextBox.Text;
foo.field2 = field2TextBox.Text;
// and so on
FormB f = new FormB();
f.ShowDialog(foo);
In FormB:
public DialogResult ShowDialog(MyClass foo)
{
Foo = foo;
field1TextBox.Text = foo.field1;
field2TextBox.Text = foo.field2
// and so on
return ShowDialog();
}
Ultimately, you may end up replacing all of that assignment with a BindingSource that binds the properties of Foo to controls in FormB.
The primary result of this design is that FormA doesn't expose any of its internal workings to FormB, and vice versa. The only information the two forms share is the well-defined set of properties in MyClass. You can replace one form completely with a new version and know that the other will still communicate properly with it.
2. Create an overload of Show() or ShowDialog() in FormB that accepts an instance of the class as an argument.
3. Make the class instance a private property of FormB.
4. Have FormB's Close() event handler update the class instance with the form's values.
Thus, FormA's button to open FormB has a Click handler like this:
MyClass foo = new MyClass();
foo.field1 = field1TextBox.Text;
foo.field2 = field2TextBox.Text;
// and so on
FormB f = new FormB();
f.ShowDialog(foo);
In FormB:
public DialogResult ShowDialog(MyClass foo)
{
Foo = foo;
field1TextBox.Text = foo.field1;
field2TextBox.Text = foo.field2
// and so on
return ShowDialog();
}
Ultimately, you may end up replacing all of that assignment with a BindingSource that binds the properties of Foo to controls in FormB.
The primary result of this design is that FormA doesn't expose any of its internal workings to FormB, and vice versa. The only information the two forms share is the well-defined set of properties in MyClass. You can replace one form completely with a new version and know that the other will still communicate properly with it.