Possible Duplicate:
I would like to control Form1 from Form2
I'm a newbie to C#
and I can't find the answer I'm looking for in google, so I'm hoping someone here could help me. I'm only practicing to transfer data (or pass, call it however you want) from a form to another.
Here's what I have:
I have 2 forms - Form1
and Form2
.
Form1
contains a textbox (named txtForm1
) and a button (named btnForm1
).
Form2
contains a textbox (named txtForm2
) and a button (named btnForm2
).
After running the application, by clicking the button btnForm1
, the user opens Form2
. The text that the user writes in the textbox (txtForm2
) should be transfered to the textbox (txtForm1
, which button is disabled) in Form1
.
How can I do this transfer?
Edited:
Okay i need to be clear that this is all the code i have:
Form1 (button which opens Form2):
private void btnForm1_Click(object sender, EventArgs e)
{
new Form2().Show();
}
Form2 (button which closes Form2):
private void btnForm2_Click(object sender, EventArgs e)
{
this.Close();
}
I have NOTHING ELSE. (I'm a total newbie)
Make a public variable and pass it the value from your text box and then onto your second form.
and when you return to the first form:
txtForm1.Text = Form2.myVar;
In your Form2 you should have some like:
Now in form1 you can acces that txtForm2 with something like:
You can easy modify the events where all this logic can occur...
in
Form1
:in
Form2
:Try this ;)
On Form1:
On form2: