Winform TreeView 节点拖动

        private void treeView_ItemDrag(object sender, ItemDragEventArgs e)
        {
            TreeNode dragNode = e.Item as TreeNode;
            DoDragDrop(dragNode, DragDropEffects.Move);
        }
        private void treeView_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.AllowedEffect;
        } 
        private void treeView_DragOver(object sender, DragEventArgs e)
        {
            TreeView tv = sender as TreeView;
            tv.SelectedNode = tv.GetNodeAt(tv.PointToClient(new Point(e.X, e.Y)));
        } 
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            TreeView tv = sender as TreeView;
            //取得被拖拽的节点
            TreeNode dragNode = e.Data.GetData(typeof(TreeNode)) as TreeNode;
            if (dragNode.Equals(tv.SelectedNode))
                return;

            if (e.Effect == DragDropEffects.Move)
            {
                if (tv.SelectedNode == null)
                {
                    tv.Nodes.Add(dragNode.Clone() as TreeNode);
                    dragNode.Remove();
                    return;
                }
                dragNode.Remove();
                tv.SelectedNode.Nodes.Add(dragNode);
            }
            dragNode.Expand();
        }

 

Winform TreeView 节点拖动

上一篇:查看端口号 netstat命令 windows


下一篇:Delphi7 调用 Windows 照片查看器打印对话框