[RESOLVED] passing data between forms
Hello guys. :)
I have a rather easy problem that I myself Can't fix, but I'm sure you guys can help me with it.
I have two forms in a project, form1 and form2. Now what I want is to call form2 from form1, and then send a value from form2 to the instance of form1 that's already open.
The way I know how to do this is with a constructor, but then I'd have to call another instance of form1. I could solve it by closing it after calling form2, that would be one solution, but not the one I'm looking for. Now, can anyone help?
The value I want from form2 must land in a textBox in form1.
Thank you guys.
Re: passing data between forms
Okay, I already solved it thanks to jmcilhinney postings in another thread.
Code in case anyone wants to see.
Code:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private Form1 F1;
public Form2(Form1 f1)
{
InitializeComponent();
this.F1 = f1;
}
private void button1_Click(object sender, EventArgs e)
{
string th = textBox1.Text;
F1.get(th);
}
}
Code:
public Form1()
{
InitializeComponent();
}
public void get(string tomar)
{
textBox1.Text = tomar;
}
private Form2 frm;
private void button1_Click(object sender, EventArgs e)
{
frm = new Form2(this);
frm.Show();
}
}