MDI 应用程序主菜单帮助

发布于 2024-09-27 00:39:08 字数 265 浏览 0 评论 0原文

我们正在开发 MDI 应用程序。我们需要做的是我有 4 个子表单和 1 个父表单。在父窗体工具箱菜单上我有 3 个按钮。添加、保存、取消。

我想做的是子表单已加载的内容。单击这些按钮时,它们应该处理子窗体上的操作。

可以说,如果我的名为 CustomerManager 的子表单已打开,那么通过按添加按钮,它基本上应该处理我的 CustomerManager 子表单。显然,我将纠正每个表单操作按钮的逻辑。

我希望我能够定义我在寻找什么。

问候 沙克斯

We are developing an MDI Application. What we need to do is that I Have 4 child forms and 1 Parent form. on the parent form ToolBox menu I have 3 buttons. 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. Obviously I will right the logic against every form action Button.

I hope I am able define what I am looking for.

Regards
Shax

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

夜还是长夜 2024-10-04 00:39:08

最好通过声明一个接口来完成此操作:

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

并让您的 MDI 子窗体实现它:

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

在您的父窗体中,为工具栏按钮实现 Click 事件,如下所示:

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

如果子窗体处于活动状态但不活动,则禁用该按钮也是一个好主意不执行该命令。您可以通过为 Application.Idle 事件编写事件处理程序来完成此操作:

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

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:

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:

    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:

    void Application_Idle(object sender, EventArgs e) {
        AddButton.Enabled = this.ActiveMdiChild is IChildCommands;
        // etc..
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文