父窗体:form2.ShowDialog(this);
子窗体的Closed事件枣团里写:this.Owner.Close();
两个窗体凳陪橘就一起关了。乱备
仅拦兆供参考:
1、父卜衡尘窗体Form1中调用子窗体Form2代码:
Form2 fr = new Form2();
fr.ShowDialog(this);
2、子窗体型禅的FormClosed事件代码:
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Form1 fr = new Form1();
fr = (Form1)this.Owner;
fr.Dispose();
fr.Close();
}
子窗体关闭的方法里NEW一下父窗体,然后调用.close()
form main
private void Form1_Load(object sender, EventArgs e)
{
Form2 f = new Form2();
f.Show();
f.FormClosed += Close;
}
private void Close(object sender, EventArgs e) //方法自定义,通过订阅委托执行
{
this.Close();
}
form child
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}