在拖动过程中,TreeView突出显示了treenode。下降

时间:2014-01-08 11:34:45

标签: .net winforms treeview

我想在拖放操作期间对Treenodes进行HotTrack。

    private const int TVIF_STATE = 0x8;
    private const int TVIS_STATEIMAGEMASK = 0xF000;
    private const int TV_FIRST = 0x1100;
    private const int TVM_SETITEM = TV_FIRST + 63;
    private const int TVIS_DROPHILITED = 8;

    [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]
    private struct TVITEM
    {
        public int mask;
        public IntPtr hItem;
        public int state;
        public int stateMask;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpszText;
        public int cchTextMax;
        public int iImage;
        public int iSelectedImage;
        public int cChildren;
        public IntPtr lParam;
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TVITEM lParam);

    public void HotTract(TreeView tv,TreeNode node)
    {
        TVITEM tvi = new TVITEM();
        tvi.hItem = node.Handle;
        tvi.mask = TVIF_STATE;
        tvi.stateMask = TVIS_DROPHILITED;
        tvi.state = TVIS_DROPHILITED;
        SendMessage(tv.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);
    }

我在DragOver事件期间调用HotTrack但选择节点。

    private void treeViewEx_DragOver(object sender, DragEventArgs e)
    {
        Point p = treeViewEx.PointToClient(new Point(e.X, e.Y));
        TreeNode node = treeViewEx.GetNodeAt(p.X, p.Y);

        if(node != null)
            HotTract(treeview,node);
       ...
    }

我认为TVITEM在HotTrack功能中没有正确填充。 谢谢。

enter image description here

enter image description here

我想看起来像第二张图片(搞笑视频)

0 个答案:

没有答案