Beispiel #1
0
        void tree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            System.Windows.Forms.TreeNode NewNode;

            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                Point pt = ((System.Windows.Forms.TreeView)sender).PointToClient(new Point(e.X, e.Y));
                if (sender != tree)
                {
                    return;
                }
                TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(pt);
                if (DestinationNode != null)
                {
                    NewNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                    TreeNode parent = DestinationNode;
                    while ((parent = parent.Parent) != null)
                    {
                        if (parent == NewNode)
                        {
                            return;
                        }
                    }
                    if (DestinationNode != NewNode)
                    {
                        NewNode.Remove();
                        DestinationNode.Nodes.Add(NewNode);
                        NewNode.EnsureVisible();
                        this.tree.SelectedNode = NewNode;
                    }
                }
            }
        }