查找节点下的上下文菜单中点击 [英] Find node clicked under context menu

查看:215
本文介绍了查找节点下的上下文菜单中点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能找出哪个节点在树列表中的上下文菜单已被激活?例如右键单击一个节点,并从菜单中选择一个选项。

How can I find out which node in a tree list the context menu has been activated? For instance right-clicking a node and selecting an option from the menu.

我不能使用的TreeView, SelectedNode 属性,因为节点仅获右键点击并没有被选中。

I can't use the TreeViews' SelectedNode property because the node is only been right-clicked and not selected.

推荐答案

您可以用鼠标点击事件添加到TreeView,然后使用GetNodeAt给出的鼠标坐标由MouseEventArgs提供选择正确的节点。

You can add a mouse click event to the TreeView, then select the correct node using GetNodeAt given the mouse coordinates provided by the MouseEventArgs.

void treeView1MouseUp(object sender, MouseEventArgs e)
{
    if(e.Button == MouseButtons.Right)
    {
        // Select the clicked node
        treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);

        if(treeView1.SelectedNode != null)
        {
            myContextMenuStrip.Show(treeView1, e.Location);
        }
    }
}

这篇关于查找节点下的上下文菜单中点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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