合并的MDI窗口菜单条项 [英] Merge menu strip items for MDI windows

查看:358
本文介绍了合并的MDI窗口菜单条项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何合并父窗体和相同的菜单名称子窗体的菜单项?

How can I merge menu items of parent form and child form with same menu name?

推荐答案

设置的的MergeAction菜单项目MatchOnly。

Set the MergeAction of the menu items to "MatchOnly".

添加

由于此可以得到有点棘手,我会添加的步骤,使一个简单的例子清单。

Because this can get a little tricky, I'll add a list of steps to make a simple example.


  • 创建一个新的Windows窗体应用程序。

  • 添加一个新的Windows窗体,并留下它的名字窗体2。

  • 开启Form1设计(如果尚未打开)。

  • 单击窗体上并设置Form1的的IsMdiContainer为True。

  • 打开工具箱,并添加的MenuStrip到Form1中。

  • 在请在此处输入框类型和放大器;文件

  • 在分项请在此处输入框中键入

  • 在分项请在此处输入框的b型

  • 您的MDI容器(Form1中)应该
    具有与项目A和b的文件菜单。

  • 双击将A项目添加
    单击处理程序

  • 添加新窗体2 {=的MdiParent这} .Show(); 的处理方法

  • 开启Form2的设计师。

  • 打开工具箱,并添加的MenuStrip
    到窗体2。

  • 注意:查看以下有关在窗体2的MenuStrip,这可能会在此点设置为False Visible属性信息

  • 在键入这里框中键入&安培;文件

  • 在分项请在此处输入框中键入
    C

  • 您的MDI子(窗体2)应该有项目C一
    文件菜单。

  • 单击在文件菜单项,并在
    的属性窗口中设置MergeAction
    到MatchOnly。

  • 运行程序。

  • Create a new Windows Forms Application.
  • Add a new Windows Form and leave its name Form2.
  • Open Form1 designer (if not already open).
  • Click on the form and set Form1's IsMdiContainer to True.
  • Open the toolbox and add a MenuStrip to Form1.
  • In the "Type Here" box type &File
  • In the sub-item "Type Here" box type A
  • In the sub-item "Type Here" box type B
  • Your MDI container (Form1) should have a File menu with items A and B.
  • Double-click the A item to add a click handler.
  • Add new Form2 { MdiParent = this }.Show(); to the handler method.
  • Open Form2 designer.
  • Open the toolbox and add a MenuStrip to Form2.
  • Note: See below for information about the Visible property on the Form2 MenuStrip, which could be set to False at this point.
  • In the "Type Here" box type &File
  • In the sub-item "Type Here" box type C
  • Your MDI child (Form2) should have a File menu with item C.
  • Click on the File menu item and in the Properties window set MergeAction to MatchOnly.
  • Run the program.

注意,文件菜单项是A和b

Notice that the File menu items are A and B.

点击文件 - > A到创建一个子窗口

Click File -> A to create a child window.

请注意,在容器上的文件菜单现在包含A, b和C。

Notice that the File menu on the container now contains A, B, and C.

另请注意,对孩子的文件菜单中是存在的,但没有项目。这是因为C被合并了。

Notice also that the File menu on the child is there, but has no items. This is because C was merged.

您现在可以在孩子的MenuStrip.Visible属性设置为false,这样子不显示菜单。这是方便离开这个作为真正的设计你的菜单时,这样你可以验证所有的子菜单项已经被正确合并(他们会从子菜单中消失)。

You can now set the child's MenuStrip.Visible property to False so that the child does not display a menu. It is handy to leave this as True when designing your menus so that you can verify that all the child menu items have been merged correctly (they will be gone from the child menu).

您可以使用MergeIndex属性来控制子项是如何被合并到容器中。

You can use the MergeIndex property to control how child items get merged into the container.

这篇关于合并的MDI窗口菜单条项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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