在子窗口form2中声明事件:
public delegate void childclose();
public event childclose closefather;
然后在它的关闭事件中触发本事件:
private void Form2_Closed(object sender, System.EventArgs e)
{
//用事件去关闭主窗口
closefather();
}
然后弹出子form2窗体(或父窗体中)的地方这样写:
private void pictureBox5_Click(object sender, EventArgs e)
{
Form2 ff=new Form2();
ff.closefather+=new childclose(this.closethis); //closethis()是父窗体中的一个方法
ff.Show();
}
public void closethis()
{
this.Close();
}
childclose需要引用using static LoginUI.FrmChangePwd;