如何使用C#4.0中添加的ContextMenuStrip子菜单项? [英] How to add sub menu items in contextmenustrip using C#4.0?

查看:845
本文介绍了如何使用C#4.0中添加的ContextMenuStrip子菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与树节点相关的一个的ContextMenuStrip控制。我在窗体本身手动创建在的ContextMenuStrip一个菜单项(例如命名为分配)。现在我想,只要用户点击此分配项添加子菜单项,它会创建的用户名列表与选中或取消选中选项子菜单项目。

I have one contextmenustrip control associated with treenode. I have created one menu item in contextmenustrip manually in the form itself(for example named as "Assign"). Now I want to add sub menu items whenever user clicks this Assign item, it will create a list of users name as a sub menu item with checked or unchecked option.

例如,当用户单击分配,然后我要动态显示的用户名。

For example, once user clicked Assign then I want to show the user name dynamically.

推荐答案

要添加一个项目,你会打电话

To add an item, you would call

myContextMenuStrip.Items.Add("Item title", null, myClickHandler);

要增加一个子菜单,你把现有项目和做同样的吧:

To add a sub-menu, you take an existing item and do the same to it:

(myContextMenuStrip.Items[0] as ToolStripMenuItem).DropDownItems.Add(...)

这篇关于如何使用C#4.0中添加的ContextMenuStrip子菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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