.NET Treeview不会在空控件上发送click事件

Kev*_*son 4 .net c# treeview events user-interface

我正在使用.NET Treeview控件(不是WPF,但是常规winforms),并且当控件内部没有节点时,右键单击事件(或任何单击事件)无法触发.根据对Stackoverflow 上另一个线程的响应,我的事件处理程序代码如下:

    private void tvTest_MouseClick(object sender, MouseEventArgs e)
    {
        // Note: this block below is needed so that the menu appears on
        // the correct node when right-clicking.
        if (e.Button == MouseButtons.Right)
        {
            tvTest.SelectedNode = tvTest.GetNodeAt(e.X, e.Y);
            if (tvTest.SelectedNode != null)
            {
                tvTestContextMenuStrip.Show(tvTest, e.Location);
            }
            else
            {
                tvTestContextMenuStrip.Show(tvTest, tvTest.Location);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

问题在于,当节点存在时这种方法很好,如果控件为空,我无法右键单击该控件并选择"添加节点"以添加到根节点.处理程序未输入AT ALL,因为我在开头设置了一个断点,并且似乎从未输入该方法.

当Treeview为空时,有谁知道如何让"某事"发生?

Sec*_*und 5

我对你描述的这个特殊问题感到好奇,所以我创建了一个新项目,然后在表单中添加了Treeview控件.

然后我为MouseDown事件创建了一个事件处理程序,并在按下右键时显示​​一条消息.如果您需要我很乐意根据请求提供的代码,基于它的大约2行和Visual Studio创建事件方法的事实我没有看到重点.