/// <summary> /// This event is fired when the user drags over a drag and drop control with the mouse. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void fileSystemTreeView_DragOver(object sender, DragEventArgs e) { //Console.WriteLine("dragover"); // Compute drag position and move image Point position = this.fileSystemTreeView.PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragMove(position.X - this.fileSystemTreeView.Left, position.Y - this.fileSystemTreeView.Top); // Get actual drop node TreeNode dropNode = this.fileSystemTreeView.GetNodeAt(position); if (dropNode == null) { e.Effect = DragDropEffects.None; return; } //if ((e.KeyState & 8) == 8) //ctrl - copy //{ // ShowToolTip(position.X, position.Y, "Copy to "); //} //else //{ // ShowToolTip(position.X, position.Y, "Move to "); //} e.Effect = DragDropEffects.Move; // if mouse is on a new node select it if (this.tempDropNode != dropNode) { DragHelper.ImageList_DragShowNolock(false); this.fileSystemTreeView.SelectedNode = dropNode; DragHelper.ImageList_DragShowNolock(true); tempDropNode = dropNode; } // Avoid that drop node is child of drag node TreeNode tmpNode = dropNode; while (tmpNode.Parent != null) { if (tmpNode.Parent == this.dragNode) { e.Effect = DragDropEffects.None; } tmpNode = tmpNode.Parent; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void scrollTimer_Tick(object sender, EventArgs e) { // get node at mouse position Point pt = this.fileSystemTreeView.PointToClient(Control.MousePosition); TreeNode node = this.fileSystemTreeView.GetNodeAt(pt); if (node == null) { return; } // if mouse is near to the top, scroll up if (pt.Y < 30) { // set actual node to the upper one if (node.PrevVisibleNode != null) { node = node.PrevVisibleNode; // hide drag image DragHelper.ImageList_DragShowNolock(false); // scroll and refresh node.EnsureVisible(); this.fileSystemTreeView.Refresh(); // show drag image DragHelper.ImageList_DragShowNolock(true); } } // if mouse is near to the bottom, scroll down else if (pt.Y > this.fileSystemTreeView.Size.Height - 30) { if (node.NextVisibleNode != null) { node = node.NextVisibleNode; DragHelper.ImageList_DragShowNolock(false); node.EnsureVisible(); this.fileSystemTreeView.Refresh(); DragHelper.ImageList_DragShowNolock(true); } } }