TreeView ignore double click only at checkbox

后端 未结 4 490
既然无缘
既然无缘 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:12

    Combining the above answers, I found this to be the best solution for me. Double clicking on a node to expand its children still works, only double clicking on a checkbox is affected and fixed:

    class MyTreeView : TreeView
    {
        protected override void WndProc(ref Message m)
        {
          if (m.Msg == 0x0203 && this.CheckBoxes)
          {
            var localPos = this.PointToClient(Cursor.Position);
            var hitTestInfo = this.HitTest(localPos);
            if (hitTestInfo.Location == TreeViewHitTestLocations.StateImage)
            {
              m.Msg = 0x0201;
            }
          }
          base.WndProc(ref m);
        }
    }
    

提交回复
热议问题