1. Pass a reference to a variable in Form1 when creating form2
2. Declare/expose a variable in Form2 that "points" to a variable on
Form1
3. Declare a delegate function in Form2 that points to a function on
Form1 that sets the variable.
Example of 1:
Form1:
private void LaunchForm2()
{
int varToReturn = 0;
Form2 form2 = new Form2(ref varToReturn);
form2.ShowDialog();
Form2:
// CONSTRUCTOR
private int form1Var;
public Form2(ref int varFrom1)
{
form1Var = varFrom1;
}
private void OnClose()
{
form1Var = DoSomething();
}
Hope this helps.
-tomas
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.