TreeView ignore double click only at checkbox

后端 未结 4 489
既然无缘
既然无缘 2020-12-16 12:41

I have a treeview with checkbox, I\'m trying to disable the double click only when this is done in the checkbox.

I found a way to totally disable the double click bu

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 13:21

    Option 1: Completely disable the double click event.
    Create a customer control

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

    and in your designer file ( form.Designer.cs ), look for where the control was created, and replace the call to TreeView constructor with your new control.

    this.treeView1 = new MyTreeView();

    Option 2: Treat a double click event as two single click events

    class MyTreeView : TreeView
    {
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0203)
            {
                m.Msg = 0x0201;
            }
            base.WndProc(ref m);
        }
    }
    

    Personally I think option 2 is more intuitive. When user clicks the check box twice, the checkbox is not checked.

提交回复
热议问题