private void trvMain_DragDrop(object sender, DragEventArgs e) { if (!e.Data.GetDataPresent(typeof(TreeNode))) { return; } TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode)); Controller item = (Controller)node.Tag; Point droppoint = trvMain.PointToClient(new Point(e.X, e.Y)); TreeNode dropnode = trvMain.GetNodeAt(droppoint); if (dropnode == null) { return; } if (node.TreeView != dropnode.TreeView) { return; } Controller destination = (Controller)dropnode.Tag; if (item == destination) { return; } item.Move(destination, true); item.Node.EnsureVisible(); trvMain.SelectedNode = item.Node; }
private void trvMain_DragOver(object sender, DragEventArgs e) { if (!e.Data.GetDataPresent(typeof(TreeNode))) { e.Effect = DragDropEffects.None; return; } TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode)); Controller item = (Controller)node.Tag; Point droppoint = trvMain.PointToClient(new Point(e.X, e.Y)); TreeNode dropnode = trvMain.GetNodeAt(droppoint); if (dropnode == null) { e.Effect = DragDropEffects.None; return; } if (node.TreeView != dropnode.TreeView) { e.Effect = DragDropEffects.None; return; } Controller destination = (Controller)dropnode.Tag; if (item == destination) { e.Effect = DragDropEffects.None; return; } if (item.Move(destination, false)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } }