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(); }