上下文菜单条

发布于 2024-08-06 09:43:48 字数 509 浏览 2 评论 0原文

我在 C# 代码中的 treeView 的各个节点上添加右键单击功能。 当用户右键单击树上的这些节点时,应该会弹出“添加”、“删除”、“重命名”等选项。现在,根据单击的节点,我使用以下语句填充菜单:

contextMenuStrip1.Items.Add("Add");

然后,如果右键单击不同的节点,我将使用以下命令:

contextMenuStrip1.Items.Add("Rename");

有一些节点必须显示这两个项目: contextMenuStrip1.Items.Add("添加"); contextMenuStrip1.Items.Add("删除");

当上下文菜单条中存在“添加”和“删除”时,如何为“添加”和“删除”编写单独的事件处理程序。我无法区分单击的是“添加”还是“删除”。目前,我正在 ContextMenuStrip 上使用“ItemClicked”事件来执行“Add”事件处理程序中的代码段,但是当单击“Delete”时也会引发此事件。任何帮助将不胜感激。

谢谢, 维伦

I am adding a right click functionality on individual nodes of a treeView in my C# code.
The options like "Add", "Delete", "Rename" should pop up when the user right clicks in those nodes on the tree. Now depending on the node that is being clicked, I am filling up the menu as using the following statememnts:

contextMenuStrip1.Items.Add("Add");

Then if a different nodes is right clicked I use the following:

contextMenuStrip1.Items.Add("Rename");

There are some nodes where both the items have to be shown:
contextMenuStrip1.Items.Add("Add");
contextMenuStrip1.Items.Add("Delete");

How do I write seperate event handlers for Add and Delete when both of them exist in the context menustrip. I am not able to differentiate whether "Add" or "Delete" was clicked. Currently I am using the "ItemClicked" event on the ContextMenuStrip to execute my piece of code in the event handler for "Add" but this evemt also gets raised when "Delete" is clicked. Any help would be appreciated.

Thanks,
Viren

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2024-08-13 09:43:48

实例化您的上下文菜单条。您将在其中添加三个 ToolstripMenuItems。每个工具条菜单项都有其自己的 OnClick 方法。根据您的上下文需要更改项目的可见性属性。

Instantiate your context menu strip. In that you will add your three ToolstripMenuItems. Each toolstrip menu item will have it's own OnClick method. Change the visibility property of an item depending on what your context requires.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文