怎样从一个form传递数据到另一个form

假设Form2的数据要传到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;

       
  

你可能感兴趣的:(Windows/.NET)