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); // bind to a method of form5 f5.Show(); } public void ChangeText(string s) {
This.label1.Text = S;} // Event processing method }
}
public partial class Form5 : Form { public delegate void mydelegate (string ss); // define a delegate type of encapsulation prototype public Form5() { InitializeComponent(); } public mydelegate change; private void button1_Click(object sender, EventArgs e) { change (this.label1.Text); // change triggered by clicking on the button } }