检测单击 TreeView 中的折叠按钮 [英] Detect click on the Collapsebutton in a TreeView

查看:24
本文介绍了检测单击 TreeView 中的折叠按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有节点的 Treeview.如果用户双击一个节点,则会打开该节点的编辑对话框,他可以在其中修改数据等.有一个问题,如果用户在节点的折叠按钮上快速单击两次 - 这也算作双击.有没有办法避免这种情况?我搜索了网络,但没有发现任何有用的信息.检测点击是否在特定区域内是无用的,因为 Treeview 是动态且可滚动的.

I have a Treeview with nodes. If the user doubleclicks a node, an editdialog for the node opens where he can modify the data etc. There is a problem, if the user clicks fastly twice onto the collapsebutton of a node - this also counts a double click. Is there a way to avoid this? I searched the Web but i found nothing really helpfull. Detecting if the click is within a specific area is useless, cause the Treeview is dynamic and scrollable.

非常感谢.

推荐答案

您只需调用 HitTest 并找出用户点击的位置.

You can just call HitTest and find out where the user clicked.

private void treeView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    var hitTest = treeView1.HitTest(e.Location);
    if (hitTest.Location == TreeViewHitTestLocations.PlusMinus)
    { 
        //expand collapse clicked
    }
}

这篇关于检测单击 TreeView 中的折叠按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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