1主窗体的代码:
namespace MyFirstApp
{
public partial class Frm_main : Form
{
public Frm_main()
{
InitializeComponent();
}
public void DiaoYong(string str)
{
this.textBox1.Text = str;
}
private void button1_Click(object sender, EventArgs e)
{
string str = this.textBox1.Text;
Frm_child f2 = new Frm_child(str);//在构造函数中,向子窗体传值。
f2.Owner = this;
f2.Show();
}
}
}
2,子窗体的代码
namespace MyFirstApp
{
public partial class Frm_child : Form
{
public Frm_child(string ss)
{
InitializeComponent();
this.textBox1.Text = ss;
}
private void button1_Click(object sender, EventArgs e)
{
string st = textBox1.Text;
Frm_main f1;
f1 = (Frm_main)this.Owner;
f1.DiaoYong(st);
this.Close();
}
}
}
浙公网安备 33010602011771号