简体   繁体   English

MDI应用程序主菜单帮助

[英]MDI Application Main Menu help

We are developing an MDI Application. 我们正在开发MDI应用程序。 What we need to do is that I Have 4 child forms and 1 Parent form. 我们需要做的是,我有4个孩子形式和1个父母形式。 on the parent form ToolBox menu I have 3 buttons. 在父窗体的“工具箱”菜单上,我有3个按钮。 Add,Save,Cancel. 添加,保存,取消。

What I want to do is What ever the child form has loaded. 我想做的是子窗体已加载的内容。 When these buttons clicked they should process the action on the child form. 单击这些按钮时,它们应在子窗体上处理操作。

LEts say, If my child form named CustomerManager is open, then by pressing the add button it should basically process my CustomerManager child form. 提示说,如果打开了名为CustomerManager的子窗体,则按添加按钮,基本上应该可以处理我的CustomerManager子窗体。 Obviously I will right the logic against every form action Button. 显然,我将针对每个表单操作Button修改逻辑。

I hope I am able define what I am looking for. 我希望我能够定义我要寻找的东西。

Regards Shax 关于Shax

This is best done by declaring an interface: 最好通过声明一个接口来完成:

public interface IChildCommands {
    void Add();
    void Save();
    void Cancel();
}

And let your MDI child form implement it: 并让您的MDI子窗体实现它:

public partial class Form2 : Form, IChildCommands {
   // Right-click IChildCommands in the editor and choose Implement Interface
   //...
}

In your parent, implement the Click event for the toolbar button like this: 在您的父级中,为工具栏按钮实现Click事件,如下所示:

    private void AddButton_Click(object sender, EventArgs e) {
        var child = this.ActiveMdiChild as IChildCommands;
        if (child != null) child.Add();
    }

It is also a good idea to disable the button if a child is active that doesn't implement the command. 如果未激活该命令的孩子处于活动状态,则禁用该按钮也是一个好主意。 Which you can do by writing an event handler for the Application.Idle event: 您可以通过为Application.Idle事件编写事件处理程序来做到这一点:

    void Application_Idle(object sender, EventArgs e) {
        AddButton.Enabled = this.ActiveMdiChild is IChildCommands;
        // etc..
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM