winform形式关闭事件形式、事件、winform

2023-09-04 01:03:50 作者:夏天来了ヽ都发春了

我有2种形式,主要与儿童。当点击主窗体上的一个按钮,子窗体被加载。我可以从主窗体,当子窗体通过订阅的子窗体关闭的事件?

I have 2 forms, Main and Child. When a button is clicked on the Main form, the Child form is loaded. Can I catch from the Main form, when the Child form is closed by subscribing to the closed event of the child form?

推荐答案

当然可以,这是pretty的简单:

Yes you can, it's pretty straightforward:

private void LoadChildForm_Click(object sender, EventArgs e)
{
    ChildForm form = new ChildForm();
    form.FormClosed += new FormClosedEventHandler(ChildFormClosed);
    form.Show();
}

void ChildFormClosed(object sender, FormClosedEventArgs e)
{
    // do something useful
}