.Net 中的 Mdi 儿童发生了变化
是否有一种简单的方法来跟踪 Mdi 子项的更改,即当它们被创建和关闭时,例如 OnMdiChildListChanged 事件(我意识到这实际上并不存在)。
我还知道我可以在 Mdi 中有一个方法来处理子表单的创建并记录它们的状态,甚至创建一个接口来定义子表单具有“NotifyParent”方法,然后在关闭时调用该方法表格,但我想知道是否有任何我可以深入研究的内置事件?
Is there a simple way of tracking the change of an Mdi's children i.e. when they are created and closed, something like an event OnMdiChildListChanged (I realise this doesn't actually exist).
I am also aware that I could have a method within my Mdi that handles the creation of child forms and logs the state of them or even create an Interface that defines that a child form has a "NotifyParent" method that is then called on close of the form, but i was wondering if there was any built in events that i could plumb into?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该管道已经存在,它用于自动更新 MDI 窗口列表(MenuStrip.MdiWindowListItem 属性)。 Form 类在 OnVisibleChanged 和 OnMdiChildActivate 方法中包含用于更新菜单的代码。不过,希望是空的,您看不到菜单项列表的更改,也无法覆盖任何管道代码。并非没有在您自己的子表单中执行类似操作并重载这些方法。
为了解决这个问题,只需在 MDI 父窗体中编写一个公共方法,您始终使用该方法来添加新的子窗口:
您甚至可以将 AddChild 设为静态,因为只有一个 MDI 父窗体。
This plumbing already exists, it is used to automatically update the MDI window list (MenuStrip.MdiWindowListItem property). The Form class has code in the OnVisibleChanged and OnMdiChildActivate methods to update the menu. Idle hope though, You can't see the menu item list change, nor can you override any of the plumbing code. Not without doing similar and overloading these methods in your own child forms.
Punt this problem, simply write a public method in your MDI parent form that you consistently use to add new child windows:
You can even make AddChild static, since there's only ever one MDI parent.
当 Mdi 子项打开或关闭时,MdiChildActivate(或 OnMdiChildActivate)将触发。
MdiChildActivate (or OnMdiChildActivate) will fire when a Mdi child is opened or closed.
您可以创建自己的事件,并自己在关联的方法中触发它。它非常简单,您可以像订阅内置事件一样订阅它。
You could create your own event, and fire it in the associated methods yourself. It's fairly simple, and you can subscribe to it just like a built in event.