怎樣從一個form傳遞數(shù)據(jù)到另一個form?假設Form2的數(shù)據(jù)要傳到Form1的TextBox。
在Form2:
// Define delegate
public delegate void SendData(object sender);
// Create instance
public SendData sendData;
在Form2的按鈕單擊事件或其它事件代碼中:
if(sendData != null)
{
sendData(txtBoxAtForm2);
}
this.Close(); //關閉Form2
在Form1的彈出Form2的代碼中:
Form2 form2 = new Form2();
form2.sendData = new Form2.SendData(MyFunction);
form2.ShowDialog();
private void MyFunction(object sender)
{
textBox1.Text = ((TextBox)sender).Text;
}
新聞熱點
疑難解答