加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

我可以在.NET Windows窗体中创建多列上下文菜单吗?

发布时间:2020-12-14 01:52:35 所属栏目:Windows 来源:网络整理
导读:我想创建一个包含多个列的上下文菜单.基本上它会像这样: First item | [common option] | All Options Second item | [common option] | All Options Third item | [common option] | All Options Fourth item | [common option] | All Options 所以基本上
我想创建一个包含多个列的上下文菜单.基本上它会像这样:

First item  | [common option] | All Options >
Second item | [common option] | All Options >
Third item  | [common option] | All Options >
Fourth item | [common option] | All Options >

所以基本上有一堆项目(在运行时生成),每个项目都可以自己启动;或使用常用选项;或者您可以获得包含所有可能选项的子菜单.

我怎样才能做到这一点?我试图滥用ContextMenuStrip和ContextMenu,但他们似乎没有任何这样的选择.我似乎还记得在某处看过多列菜单……

我更喜欢Windows Forms解决方案,因为我没有任何WPF经验.哦,当点击通知区域(aka系统托盘)中的图标时,将打开此上下文菜单.

解决方法

我不知道ContextMenuStrip,这是一个完全用.NET代码构建的菜单,但你绝对可以使用ContextMenu来做这件事,它是本机系统菜单的包装器.

关键是为各个菜单项设置MFT_MENUBREAK或MFT_MENUBARBREAK标志,这些标志分别作为MenuItem class包装器中的属性公开:MenuItem.BreakMenuItem.BarBreak.

前者只是将菜单项放在一个新列中,而后者将该项放入一个新列中,并将该列与蚀刻的垂直线分开.

从MSDN示例:

public void CreateMyMenus()
{
    // Create three top-level menu items.
    MenuItem menuItem1 = new MenuItem("&File");
    MenuItem menuItem2 = new MenuItem("&New");
    MenuItem menuItem3 = new MenuItem("&Open");

    // Set the BarBreak property to display horizontally.
    menuItem2.BarBreak = true;
    menuItem3.BarBreak = true;

    // Add menuItem2 and menuItem3 to the menuItem1's list of menu items.
    menuItem1.MenuItems.Add(menuItem2);
    menuItem1.MenuItems.Add(menuItem3);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读