public partial class Form4 : Form { public string str = ""; public Form4() { InitializeComponent(); } private void Form4_Load(object sender, EventArgs e) { Form5 f5 = new Form5(); f5.change = new Form5.mydelegate(ChangeText);//将方法绑定到form5中 f5.Show(); } public void ChangeText(string s) {
this.label1.Text=s;}//事件处理的方法 }
}
public partial class Form5 : Form { public delegate void mydelegate(string ss);//定义委托原型所封装的方法类型 public Form5() { InitializeComponent(); } public mydelegate change; private void button1_Click(object sender, EventArgs e) { change(this.label1.Text);//通过点击按钮来触发change } }