当MDI子被关闭C#MDI父检测? [英] C# MDI Parent detect when MDI Child is closing?

查看:135
本文介绍了当MDI子被关闭C#MDI父检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试检测,对MDI父,当我的MDI子窗体关闭,并做出相应的反应。直到MDI子关闭MDI父不应该做任何事情。这里是我的代码,我不能确定我在做什么错的,但我加的形式封闭事件方法永远不会被调用...

I'm attempting to detect, on the MDI parent, when my MDI child form closes, and react accordingly. The MDI parent shouldn't do anything until the MDI child closes. Here is my code, I'm unsure as to what I'm doing wrong, but the form closed event method I added is never being called...

以下代码是在MDI父类,如果不明显。

The following code is in the MDI parent class, if that wasn't obvious.

    private void keyValidation()
    {
        if (Properties.Settings.Default.Unlock == true)
            return;
        else
        {
            menu.Enabled = false;
            statusStrip.Enabled = false;

            ValidationForm vf = new ValidationForm();
            vf.MdiParent = this;
            vf.Show();
            vf.FormClosed += new FormClosedEventHandler(validationForm_FormClosed);
        }
    }

    void validationForm_FormClosed(object sender, FormClosedEventArgs e)
    {
        MessageBox.Show("Got here");
        if (Properties.Settings.Default.Unlock == true)
        {
            menu.Enabled = true;
            statusStrip.Enabled = true;
        }
    }



感谢您的帮助!

Thanks for any help!

推荐答案

虽然这并没有真正解决你指的是,从使用情况来看这个问题,你可能要考虑开放验证形式一个模式对话框,而不是作为一个MDI子。

While this doesn't really address the problem you're referring to, judging from the use case, you may want to consider opening the Validation form as a modal dialog instead of as an MDI child.

您可以使用这个表单的的 的ShowDialog() 方法,你必须显示()现在。请记住,的ShowDialog()也可以返回的 的DialogResult 如果你将它们分配给其他形式上的按钮。

You can do this using the form's ShowDialog() method where you have Show() now. Keep in mind that ShowDialog() can also return a DialogResult if you assign them to buttons on the other form.

这篇关于当MDI子被关闭C#MDI父检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆