Detect click on the Collapsebutton in a TreeView

2019-03-01 03:49发布

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.

Many thanks in advance.

标签: c# treeview
1条回答
祖国的老花朵
2楼-- · 2019-03-01 04:35

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
    }
}
查看更多
登录 后发表回答