C# 问题:在 MDIParent 表单中动态禁用 ToolStripMenuItems/ToolStripButtons:哪个事件?
对于以下问题的任何指导将不胜感激。我应该在哪个 MDIParent 事件中禁用项目/按钮?活性?在程序启动时,我希望禁用按钮。如果没有活动的 MDIChildren,我希望禁用按钮。当我启动子表单时,我想测试该子表单的数据。如果它是空白表单,我希望按钮保持禁用状态。目前,我的代码位于 MdiChildActivated 事件处理程序中。感谢您抽出时间。
Any guidance on the following issue would be greatly appreciated. In which MDIParent event should I disable the items/buttons? Activated? On program Launch, I want the buttons disabled. If there are no active MDIChildren, I want the buttons disabled. When I launch a child form, I want to test that child form for data. If it is a blank form, I want the buttons to remain disabled. I currently have my code in the MdiChildActivated Event Handler. Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用激活事件禁用所有项目/按钮。在 MDIChildActive 事件中,我测试空白表单。如果不为空,我将启用项目/按钮。
I used the Activate Event to disable all items/buttons. In the MDIChildActive Event I test for a blank form. If not blank, I enable the items/buttons.
我将使用 MDI 父窗体的 MdiChildActivate 事件:
http://msdn.microsoft.com/ en-us/library/system.windows.forms.form.mdichildactivate.aspx
请注意该页面中的此注释:
您可以使用此事件来执行任务,例如更新 MDI 子窗体的内容和 根据激活的 MDI 子窗体的状态更改 MDI 父窗体中可用的菜单选项。
另请注意,当子项关闭时也会调用此事件(来自 MSDN):
当在 MDI 应用程序中激活或关闭多文档界面 (MDI) 子窗体时发生。
这意味着在这种情况下您可以执行以下操作:
menuButton.Enabled = (this.MdiChildren.Length > 0);
或者,如果您需要检查所有子表单的某些条件,并且其中一个子表单需要启用按钮,则启用该按钮:
I would use MDI Parent form's MdiChildActivate event:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.mdichildactivate.aspx
Please note this remark from that page:
You can use this event to perform tasks such as updating the contents of the MDI child form and changing the menu options available in the MDI parent form based on the status of the MDI child form that is activated.
Also note that this event is also called when a child is closed (from MSDN):
Occurs when a multiple-document interface (MDI) child form is activated or closed within an MDI application.
That means that in this event you could do something like:
menuButton.Enabled = (this.MdiChildren.Length > 0);
or, if you need to check all child forms for some condition, and if one of children needs enabled button then enable the button: