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

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

问题描述

我有一个与 treenode 关联的上下文菜单控件.我在表单本身中手动创建了 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天全站免登陆