简体   繁体   English

c# treeview 中的 MouseDoubleClick 事件仅在双击节点时发生

[英]MouseDoubleClick event in c# treeview only occur when node is double clicked

Event only occur when node is double clicked but i want to trigger double click even when no node is present in treeview.事件仅在双击节点时发生,但即使 treeview 中不存在节点,我也想触发双击。 I want to copy data from another treeview so event is required to trigger.我想从另一个 treeview 复制数据,因此需要触发事件。

You can try to achieve it by subscribing to MouseUp event.您可以尝试通过订阅MouseUp事件来实现它。

private DateTime t1 = DateTime.Now;

private void treeView1_MouseUp(object sender, MouseEventArgs e)
{
    var t2 = t1;
    t1 = DateTime.Now;

    if ((t1 - t2).TotalMilliseconds <= SystemInformation.DoubleClickTime)
    {
        TreeViewHitTestInfo hti = treeView1.HitTest(e.Location);

        if (hti.Node == null || !hti.Node.Bounds.Contains(e.Location))
        {
            MessageBox.Show("empty area double-click");
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM