Winforms:在我的应用程序中打开表单时是否有通知? [英] Winforms: Is there a way to be informed whenever a form gets opened in my application?

查看:121
本文介绍了Winforms:在我的应用程序中打开表单时是否有通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主窗体上有一个切换到窗口按钮,只有当其他窗口(在我的应用程序中)打开时,我才想启用它。每当窗体打开或关闭时,我的主窗体是否可以挂起? (例如,可能是某种方式来跟踪Application.OpenForms的更改?)

I have a "Switch to window" button on my main form that I'd like to be enabled only when other windows (in my app) are open. Is there some sort of event that is raised whenever a form is opened or closed that my main form can hook? (For example, perhaps some sort of way to track when Application.OpenForms has changed?)

(我知道如果这个功能在一个菜单项中,我可以简单地执行Application.OpenForms检查菜单是否点击,但此按钮不在菜单中。)

(I understand that if this functionality were in a menu item, I could simply do the Application.OpenForms check when the menu was clicked, but this button is not in a menu.)

推荐答案

您可以使用 MessageFilter ,并监视WM_SHOWWINDOW和WM_CLOSE消息。

You could use a MessageFilter and monitor for WM_SHOWWINDOW and WM_CLOSE messages.

这篇关于Winforms:在我的应用程序中打开表单时是否有通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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