I have 2 forms, and the second form is meant to be active WHILE the first form is still active.
I need to pass the string value from textBox1.Text on Form1 to textBox1.Text on Form2.
How would such me done without reopening Form1 from Form2?
I have 2 forms, and the second form is meant to be active WHILE the first form is still active.
I need to pass the string value from textBox1.Text on Form1 to textBox1.Text on Form2.
How would such me done without reopening Form1 from Form2?
Is this what you meant?
Form1 form1 = new Form1();
Form1 form2 = new Form2();
form1.Show();
form2.Show();
form2.Button1_Click += delegate {form2.textbox1.Text = form1.textbox1.Text};
How about this?
class Form1 : Form
{
void ButtonOpenForm2_Click(object s, EventArgs ea)
{
this.form2 = new Form2(this);
this.form2.Show();
}
}
class Form2 : Form
{
public Form2(Form1 form1)
{
form1.textbox1.TextChanged += delegate {this.textbox1.Text = form1.textbox1.Text};
}
}
static void Main()
{
Form1 form1 = new Form1();
form1.Show();
}
public class Form2 : Form
{
//This property will hold the text, so populate the textbox from it
string TextProperty {get;set;}
public form2(string textFromForm1)
{
TextProperty = textFromForm1;
}
}
Now on form1:
Form2 form2 = new Form2(textbox1.Text);
form2.ShowDialog();