在.NET中合并菜单 - 它到底出了什么问题?!?! [英] Merging Menus in .NET - what the hell is wrong with it??!?!

查看:56
本文介绍了在.NET中合并菜单 - 它到底出了什么问题?!?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

每个MDI应用程序的标准内容 - 合并菜单。但看起来微软无法做到这一点!

The standard thing for every MDI application - merging menus. But it looks like Microsoft is UNABLE TO DO IT RIGHT!

到底是怎么回事?! .NET 3.5发布后已经过去了11年,这个愚蠢的bug仍未解决!为什么?!

What the hell is going on?! 11 years have passed after .NET 3.5 released and this stupid bug is still not fixed! Why?!

在父MDI表单中,我有一种带有典型子菜单的标准主菜单:文件,编辑,工具,帮助。

In a parent MDI form I have a kind of standard main menu with typical submenus: File, Edit, Tools, Help.

我需要在"帮助"之前插入MDI子表单中的所有主菜单。 MDI父级菜单项!不是在"帮助"之后MDI父母的子菜单!

I need that any main menus in MDI child forms to be INSERTED BEFORE the "Help" menu item in MDI parent! Not after the "Help" submenu in MDI parent!

重要的问题是 - 为什么MICROSOFT仍然不能做这么简单的事情?!

The rethoric question is - WHY MICROSOFT STILL NOT ABLE TO DO SUCH SIMPLE THING?!?

主要问题 - 如何做到这一点?!是否可以
只使用表单设计器
,所以不需要为手动菜单合并编写大量代码?

The main question - HOW TO DO THIS?! Is it possible to do it with only form designer, so without writing tons of code for manual menus merging?

我已经拥有的东西:

1)MDI父母的MenuStrip有顶部子菜单:File(mergeIdx = 10),Window(mergeIdx) = 20),工具(mergeIdx = 30),帮助(mergeIdx = 99)。

1) MDI parent has MenuStrip with top submenus: File(mergeIdx=10), Window(mergeIdx=20), Tools(mergeIdx=30), Help(mergeIdx=99).

2)4种不同类型的MDI表单,每种表单都有自己的MenuStrip,其中mergeIdx = 40,mergeAction = Insert 。

2) 4 different types of MDI forms each with own MenuStrip which has mergeIdx=40, mergeAction=Insert.

我已经在MDI子项中的MDI父级中尝试了所有可能的mergeAction值组合 - 它不起作用!在所有情况下,总是在"帮助"之后从MDI孩子追加菜单。 MDI父级中的菜单项。 :(

I have already tried all possible combinations of mergeAction values in MDI parent in MDI childs - it does not work! In all cases it is always append menu from MDI child after the "Help" menu item in MDI parent. :(

我没有想法。也许只留下一个选项 - 写大量的代码来进行手动菜单合并。:\ 



I run out of ideas. Maybe only one option is left - write tons of code to do manual menus merging. :\ 

提前谢谢。

WBR,Dmitry。

WBR, Dmitry.

推荐答案

嗨德米特里,

要解决这个问题,我们只需要设置 MenuStrip"MDIChild"中ToolStripMenuItems的" MergeIndex "

To solve this issue, we only need to set the"MergeIndex" of the ToolStripMenuItems in MenuStrip "MDIChild".

这里我们假设MenuStrip中有两个项目。

Here we assume that there are two items in the MenuStrip.

并按以下方式设置属性:

And set the properties as follows:

" Others" ToolStripMenuItem

"Others" ToolStripMenuItem:

"退出" ToolStripMenuItem

C#代码:

Form1(MDIParent):

Form1(MDIParent):

    public partial class Form1 : Form
    {
        public interface ITools
        {
            ToolStrip CipherToolStrip
            {
                get;
            }
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.MdiParent = this;
            f2.Show();
        }

        private void Form1_MdiChildActivate(object sender, EventArgs e)
        {
            ToolStripManager.RevertMerge(MDIParent);
            if (this.ActiveMdiChild != null)
            {
                if ((ActiveMdiChild as ITools).CipherToolStrip != null)
                {
                    ToolStripManager.Merge((ActiveMdiChild as ITools).CipherToolStrip, MDIParent);
                }
            }

            if (MDIParent.Items.Count > 0)
                MDIParent.Visible = true;
            else
                MDIParent.Visible = false;
        }
    }

Form2(MDIChild):

Form2(MDIChild):

    public partial class Form2 : Form, Form1.ITools
    {
        public ToolStrip CipherToolStrip
        {
           get
            {
                return MDIChild;
            }
        }

        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            MDIChild.Visible = false;
            ControlBox = false;
        }
    }

结果:

问候,

Stanly


这篇关于在.NET中合并菜单 - 它到底出了什么问题?!?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆