方法一: 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); }