简体   繁体   English

C# 将双击改为两次单击

[英]C# Change double click into two single clicks

I have been working on an addin with a treeview.我一直在研究带有树视图的插件。 But a bug in the treeview control messes up double clicks because the next click get ignored.但是树视图控件中的一个错误会使双击变得混乱,因为下一次单击被忽略了。 What I want to achieve is a double click that is read as two single clicks.我想要实现的是双击读取为两次单击。 I have found a solution to this where a double click is always read as a single click.我找到了一个解决方案,其中双击始终被视为单击。 Code Below:代码如下:

class MyTreeView : TreeView
{
    protected override void WndProc(ref System.Windows.Forms.Message m)
    {
        if (m.Msg == 0x0203)
        {
            m.Result = IntPtr.Zero;
        }
        else
        {
            base.WndProc(ref m);
        }
    }
}

This WndProc method is not my wheelhouse and will probably not be for a long time.这个 WndProc 方法不是我的驾驶室,可能不会持续很长时间。 But for this addin I need a quick solution.但是对于这个插件,我需要一个快速的解决方案。 Can somebody provide an answer on how to achieve a double click to two single clicks?有人可以提供有关如何实现双击到两次单击的答案吗?

After some more searching I have found a solution.经过更多的搜索,我找到了解决方案。 See code below:见下面的代码:

protected override void WndProc(ref System.Windows.Forms.Message m)
{
    if (m.Msg == 0x203) m.Msg = 0x201;
    base.WndProc(ref m);
}

The Treeview in windows forms has two events: Click and DoubleClick. Windows 窗体中的 Treeview 有两个事件:Click 和 DoubleClick。 You can make Doubleclick execute the Click event twice like this:您可以让 Doubleclick 执行两次 Click 事件,如下所示:

public Form1()
    {
        InitializeComponent();
        treeView1.Click += TreeView1_Click;
        treeView1.DoubleClick += TreeView1_DoubleClick;
    }

    private void TreeView1_DoubleClick(object sender, EventArgs e)
    {
        TreeView1_Click(sender, e);
        TreeView1_Click(sender, e);
    }

    private void TreeView1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.Print("Click");
    }

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

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