主窗体.cs
protected void FormTitleChanged(string title)
{
this.Text = title;
}
private void button3_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.TitleChanged = new Form3.TitleChangedHandler(FormTitleChanged);
f3.Show();
}
子窗体.cs
public partial class Form3 : Form
{
// 声明和定义委托
public delegate void TitleChangedHandler(string title);
public TitleChangedHandler TitleChanged;
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (TitleChanged != null)
TitleChanged("3 通过“委托代理”传递信息"); //委托调用
}
}