void TemplateTree_DragOver(object sender, DragEventArgs e) { Point point = TemplateTree.PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragMove(point.X, point.Y); e.Effect = DragDropEffects.Move; }
private void suiteTreeView_DragOver(object sender, DragEventArgs e) { Point formP = this.PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragMove(formP.X - this.suiteTreeView.Left, formP.Y - this.suiteTreeView.Top); TreeNode dropNode = this.suiteTreeView.GetNodeAt(this.suiteTreeView.PointToClient(new Point(e.X, e.Y))); if (dropNode == null) { e.Effect = DragDropEffects.None; return; } e.Effect = DragDropEffects.Move; if (this.tempDropNode != dropNode) { DragHelper.ImageList_DragShowNolock(false); this.suiteTreeView.SelectedNode = dropNode; DragHelper.ImageList_DragShowNolock(true); tempDropNode = dropNode; } TreeNode tmpNode = dropNode; while (tmpNode.Parent != null) { if (tmpNode.Parent == this.dragNode) { e.Effect = DragDropEffects.None; } tmpNode = tmpNode.Parent; } }
private void BetterTreeView_DragOver(object sender, DragEventArgs e) { DragScroll(); // Compute drag position and move image Point formP = PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragMove(formP.X - Left, formP.Y - Top); // Get actual drop node TreeNode dropNode = GetNodeAt(PointToClient(new Point(e.X, e.Y))); // Make sure we have a node. if (dropNode == null) { e.Effect = DragDropEffects.None; return; } if (tempDropNode != dropNode) { DragHelper.ImageList_DragShowNolock(false); SelectedNode = dropNode; DragHelper.ImageList_DragShowNolock(true); tempDropNode = dropNode; } // Make sure that we aren't dropping onto a child node. TreeNode tmpNode = dropNode; while (tmpNode.Parent != null) { if (tmpNode.Parent == dragNode) { e.Effect = DragDropEffects.None; return; } tmpNode = tmpNode.Parent; } // Allow any event handlers a chance to cancel the drag/drop. DragOverNodeEventArgs args = new DragOverNodeEventArgs(dragNode, dropNode); if (DragOverNode != null) { DragOverNode(this, args); } if (args.Cancel) { e.Effect = DragDropEffects.None; return; } e.Effect = DragDropEffects.All; }
protected override void OnDragOver(DragEventArgs drgevent) { try { // Compute drag position and move image Point formP = this.PointToClient(new Point(drgevent.X, drgevent.Y)); //DragHelper.ImageList_DragMove(formP.X - this.Left, formP.Y - this.Top); DragHelper.ImageList_DragMove(formP.X, formP.Y); // Get actual drop node TreeNode dropNode = this.GetNodeAt(this.PointToClient(new Point(drgevent.X, drgevent.Y))); if (dropNode == null) { //Verificar //drgevent.Effect = DragDropEffects.None; return; } drgevent.Effect = DragDropEffects.Move; // if mouse is on a new node select it if (this.tempDropNode != dropNode) { DragHelper.ImageList_DragShowNolock(false); this.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) { drgevent.Effect = DragDropEffects.None; } tmpNode = tmpNode.Parent; } } catch (Exception e) { ACSLog.InsertLog(MessageBoxIcon.Error, e); } }
private void treeView1_DragOver(object sender, DragEventArgs e) { // Compute drag position and move image Point formP = this.PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragMove(formP.X - this.treeView1.Left, formP.Y - this.treeView1.Top); // Get actual drop node TreeNode dropNode = this.treeView1.GetNodeAt(this.treeView1.PointToClient(new Point(e.X, e.Y))); if (dropNode == null) { e.Effect = DragDropEffects.None; return; } e.Effect = DragDropEffects.Move; // if mouse is on a new node select it if (this.tempDropNode != dropNode) { DragHelper.ImageList_DragShowNolock(false); this.treeView1.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> /// Gets called when the mouse moves with a dragged item. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _DragOver(object sender, DragEventArgs e) { var treeView = sender as TreeView; if (treeView == null || treeView != this._treeView) { return; } var currentScreenPoint = new Drawing.Point(e.X, e.Y); // Compute drag position and move image var form = treeView.FindForm(); if (form == null) { DragHelper.ImageList_DragShowNolock(false); } else { var tvP = treeView.GetLocationOnForm(); var formP = form.PointToClient(currentScreenPoint); formP.Offset(-tvP.X, -tvP.Y); DragHelper.ImageList_DragMove(formP.X, formP.Y); } var hoveredNode = treeView.GetNodeAt(treeView.PointToClient(currentScreenPoint)); if (hoveredNode == null) { return; } var draggedNode = this._draggedNode; #region If hoveredNode is a child of the dragged node then cancel if (hoveredNode.IsChildOf(draggedNode)) { this.NodeMap = string.Empty; return; } #endregion // A bit long, but to summarize, process the following code only if the nodeover is null // and either the nodeover is not the same thing as nodemoving UNLESSS nodeover happens // to be the last node in the branch (so we can allow drag & drop below a parent branch) if (hoveredNode == draggedNode && (hoveredNode.Parent == null || hoveredNode.Index != (hoveredNode.Parent.Nodes.Count - 1))) { return; } var offsetY = treeView.PointToClient(Cursor.Position).Y - hoveredNode.Bounds.Top; this._ResetDraw(); if (!this._IsFolderNode(hoveredNode)) { #region Standard Node if (offsetY < (hoveredNode.Bounds.Height / 2)) { //this.lblDebug.Text = "top"; #region Store the placeholder info into a pipe delimited string this.SetNewNodeMap(hoveredNode, false); if (this.SetMapsEqual()) { return; } #endregion this._SetAndDraw(PlaceHolderType.LeafTop, hoveredNode); } else { //this.lblDebug.Text = "bottom"; #region Allow drag drop to parent branches TreeNode ParentDragDrop = null; // If the node the mouse is over is the last node of the branch we should allow // the ability to drop the "nodemoving" node BELOW the parent node if (hoveredNode.Parent != null && hoveredNode.Index == (hoveredNode.Parent.Nodes.Count - 1)) { var XPos = treeView.PointToClient(Cursor.Position).X; if (XPos < hoveredNode.Bounds.Left) { ParentDragDrop = hoveredNode.Parent; var image = ParentDragDrop.GetImage(); if (XPos < (ParentDragDrop.Bounds.Left - (image?.Size.Width ?? 0))) { if (ParentDragDrop.Parent != null) { ParentDragDrop = ParentDragDrop.Parent; } } } } #endregion #region Store the placeholder info into a pipe delimited string // Since we are in a special case here, use the ParentDragDrop node as the current "nodeover" this.SetNewNodeMap(ParentDragDrop ?? hoveredNode, true); if (this.SetMapsEqual()) { return; } #endregion this._SetAndDraw(PlaceHolderType.LeafBottom, hoveredNode, ParentDragDrop); } #endregion } else { #region Folder Node if (offsetY < (hoveredNode.Bounds.Height / 3)) { //this.lblDebug.Text = "folder top"; #region Store the placeholder info into a pipe delimited string this.SetNewNodeMap(hoveredNode, false); if (this.SetMapsEqual()) { return; } #endregion this._SetAndDraw(PlaceHolderType.FolderTop, hoveredNode); } else if ((hoveredNode.Parent != null && hoveredNode.Index == 0) && (offsetY > (hoveredNode.Bounds.Height - (hoveredNode.Bounds.Height / 3)))) { //this.lblDebug.Text = "folder bottom"; #region Store the placeholder info into a pipe delimited string this.SetNewNodeMap(hoveredNode, true); if (this.SetMapsEqual()) { return; } #endregion this._SetAndDraw(PlaceHolderType.FolderTop, hoveredNode); } else { //this.lblDebug.Text = "folder over"; if (hoveredNode.Nodes.Count > 0) { DragHelper.ImageList_DragShowNolock(false); hoveredNode.Expand(); this._SetAndDraw(PlaceHolderType.AddToFolder, hoveredNode); } else { #region Prevent the node from being dragged onto itself if (draggedNode == hoveredNode) { return; } #endregion #region If hoveredNode is a child then cancel if (hoveredNode.IsChildOf(draggedNode)) { this.NodeMap = string.Empty; return; } #endregion #region Store the placeholder info into a pipe delimited string this.SetNewNodeMap(hoveredNode, false); this.NewNodeMap = this.NewNodeMap.Insert(this.NewNodeMap.Length, _NODEMAP_DELIMITER + "0"); if (this.SetMapsEqual()) { return; } #endregion this._SetAndDraw(PlaceHolderType.AddToFolder, hoveredNode); } } #endregion } }