blah blah blah is here! blah blah » Close

up1down
link

Hi,

how can i pass a value to a form

ex. in form1 i have var1,
how can i send it to the form2 giving var1,
and when finished setting that variable on form2,
give it back to form1 with the change.

Thanks,

Daniel

last answered one year ago

1 answers

link

There are many ways to do this sort of thing. Here's one of them:

class Form1: Form
{
internal int var1 = 1; // say

// in some method
Form2 f2 = new Form2();
f2.Show();
}

class Form2 : Form
{
// in some method
Form1 f1 = (Form1)Application.OpenForms["Form1"];
f1.var1 = 42;
}

Feedback