1. Set the Modifies of Form1.textBox2 to internal.2. Define a private variable in Form2 private Form1 _myParent;3.Create a constructor for Form2 public class Form2(Form1 aForm) { _myParent = aForm;}4. Open Form2 in Form1: Form2 f2 = new Form2(this); f2.Show();5. You can set the value of Form1.textBox.Text with the _myParent in Form2 now._myParent.textBox2.Text = "";6. Sothing just like this, you can modify it for your self.
Oh,So quickly. I overkilled.
the first form: Form2 frm = new Form2(); frm.somename = textBox2.Text.Trim().ToString();the second form: private string anothername; public string somename { set { anothername= value ; } } Form2.textBox1.text=anothername;
at last "Form2" can be removed.
public class Form2: System.Windows.Forms.Form private Form1 form1 public Form2(Form1 form1) { this.form1=form1 }然后就可以用 form1.textBox2.text=this.textBox1.text
然后在Form2类里适当的事件中触发:this._myParentForm.textBox2.text=this.textBox1.text
private Form1 _myParent;3.Create a constructor for Form2
public class Form2(Form1 aForm)
{ _myParent = aForm;}4. Open Form2 in Form1:
Form2 f2 = new Form2(this);
f2.Show();5. You can set the value of Form1.textBox.Text with the _myParent in Form2 now._myParent.textBox2.Text = "";6. Sothing just like this, you can modify it for your self.
I overkilled.
Form2 frm = new Form2();
frm.somename = textBox2.Text.Trim().ToString();the second form:
private string anothername;
public string somename
{
set
{
anothername= value ;
}
}
Form2.textBox1.text=anothername;
public class Form2: System.Windows.Forms.Form
private Form1 form1
public Form2(Form1 form1)
{
this.form1=form1
}然后就可以用
form1.textBox2.text=this.textBox1.text