子窗体定义一个委托,父窗体实例化子窗体时注册子窗体的委托事件(具体方法实现父窗口的控件变化),子窗体关闭时调用事件方法。
父窗体:
private void testToolStripMenuItem_Click(object sender, EventArgs e)
{
FormChild child = new FormChild();
//新建一个窗体
child.MdiParent = this;
child.CloseWindow += new Action(sub_CloseWindow);
child.Show();
}
void sub_CloseWindow()
{
//改变父窗体控件内容
}
子窗体:
public FormChild()
{
InitializeComponent();
}
public event Action CloseWindow;
private void FormChild_FormClosing(object sender, FormClosingEventArgs e)
//子窗体退出事件
{
Action handler = CloseWindow;
if (handler != null) handler();
}