Passing data from one form to another
Hi,
I have a windows form and when I press a button I want the second form to appear and show me a value which is already in the first one.
For example, in Form 1 I have public int number = 1;
and when I press the button in Form 1, the other form will appear and show me 1. The only problem is that I don't know how to access the values of the first form.
On Form 2, I tried to create an instance of Form1 but didn't work, because I shouldn't instantiate another object but instead I have to use the one that I created. Any idea how to do that?
Thanks for your help.
Jan MontanoPosted Jul 18, 2007, 6:07 AM
You could just pass the values needed in Form2's constructor. Or modify a public variable/property of Form2, when you're still in Form1's button click.
Or pass Form1 instead on Form2's constructor if you want to get values from form1 interactively.
Your Form2 should look something like this:
public partial class Form2 : Form
{
}