C# 问题:在 MDIParent 表单中动态禁用 ToolStripMenuItems/ToolStripButtons:哪个事件?

发布于 2024-08-30 16:16:52 字数 184 浏览 6 评论 0原文

对于以下问题的任何指导将不胜感激。我应该在哪个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千秋岁 2024-09-06 16:16:52

我使用激活事件禁用所有项目/按钮。在 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.

小糖芽 2024-09-06 16:16:52

我将使用 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);

或者,如果您需要检查所有子表单的某些条件,并且其中一个子表单需要启用按钮,则启用该按钮:

    void Form1_MdiChildActivate(object sender, EventArgs e)
    {
        foreach (Form child in MdiChildren)
        {
            if (IsToolbarButtonNeededForThisForm(child))
            {
                toolButton.Enabled = true;
                break;
            }
        }
        toolButton.Enabled = false;

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:

    void Form1_MdiChildActivate(object sender, EventArgs e)
    {
        foreach (Form child in MdiChildren)
        {
            if (IsToolbarButtonNeededForThisForm(child))
            {
                toolButton.Enabled = true;
                break;
            }
        }
        toolButton.Enabled = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文