public Form1()
{
InitializeComponent();
frm2.FormClosing += new FormClosingEventHandler(form2_FormClosing);
frm2.Show();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
form2_FormClosing(null, e);
}
private void form2_FormClosing(object? sender, FormClosingEventArgs e)
{
// This will only get called "directly" when the second form is
// closed otherwise it will always be called from Form1_FormClosing.
}
1条答案
按热度按时间igetnqfo1#
第二个窗体是窗体/类本身的示例,因此除非您将其设置为MDI应用程序,否则第二个窗体将不会接收Closing或Closed事件,因为程序正在退出。
您可以从Form 1的关闭事件点击进入第二个窗体FormClosing事件,这是许多方法之一: