构造函数法:
public partial class Form1 : Form
{
public string str;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
str = this.textBox1.Text;
Form2 form2 = new Form2(str);
form2.ShowDialog();
}
}
public partial class Form2 : Form
{
public string jieshou;
public Form2(string chuanlai)
{
InitializeComponent();
jieshou = chuanlai;
}
private void button1_Click(object sender, EventArgs e)
{
this.textBox2.Text = jieshou;
}
}
父子窗口法:
public partial class Form1 : Form
{
public string str;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Owner = this;
str = this.textBox1.Text;
form2.ShowDialog();
}
}
public partial class Form2 : Form
{
public Form2( )
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 form1=(Form1)this.Owner;
this.textBox2.Text = form1.str;
}
}