方法一: A to B 函数
设置FormB 为 带参数的构造函数this
public Form2( object msg) { InitializeComponent(); }
方法二: A to B orm
定义一个public 函数blog
public void Receive(string Msg) { txtInfo.Text = Msg; this.Show(); }
方法三: 两个窗口间相互传值string
须要互传时 方法二能够实现 参数传递 可是不能及时更新接收窗口控件的显示,因此建议使用委托的方法。it
Form1:event
private void btnShow_Click(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.MyEvent += new Form2.MyDelegate(MyEvent); f2.Receive(txtInfo1.Text); } void MyEvent(string msg) { txtInfo1.Text = msg; }
Form2:class
public delegate void MyDelegate(string msg); public event MyDelegate MyEvent; private void btnSend_Click(object sender, EventArgs e) { MyEvent(txtInfo.Text); }