Form1代码如下:
private void button1_Click(object sender, EventArgs e) { Form2 fr2 = new Form2(ShowMag);//传递方法 fr2.Show(); } //赋值方法 void ShowMag(string str) { this.label1.Text = str; }
Form2代码如下:
//声明一个委托,delegate public delegate void DelTest(string str); public partial class Form2 : Form { public DelTest _del; //构造方法 public Form2(DelTest del) { this._del = del; InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { _del(this.textBox1.Text); } }