public DragDropResult(TreeNodePro[] dragdropNodes, TreeNodePro dropNode, DragDropResultType dropResultType)
 {
     _dragdropNodes = dragdropNodes;
     _dropPutNode = dropNode;
     _dropResultType = dropResultType;
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            //如果其顺序有效,且在拖动,则在拖拽处画条横线,指示插入点
            if (CanOrder && _isDragDrop)
            {
                Point mousePosition = PointToClient(Control.MousePosition);
                TreeNodePro mouseNode = (TreeNodePro)this.GetNodeAt(mousePosition);
                bool mouseNodeIsNull = false;

                ///鼠标当前位置没有TreeNode,那么认为鼠标在最后一个TreeNode之后
                if (mouseNode == null)
                {
                    mouseNodeIsNull = true;
                    mouseNode = (TreeNodePro)this.Nodes[this.Nodes.Count - 1];
                }

                if (!mouseNodeIsNull)
                {
                    ///检测拖拽结果
                    DragDropResultType dropResultType = GetDragDropResult();

                    if (mouseNode != _dropResultNode || dropResultType != _dropResultType)
                    {
                        switch (dropResultType)
                        {
                            ///鼠标在目标节点之前
                            case DragDropResultType.Before:
                                {
                                    _lineBeginPoint = new Point(mouseNode.Bounds.X - 20, mouseNode.Bounds.Y);
                                    _lineEndPoint = new Point(mouseNode.Bounds.X + _InsertLineWidth, mouseNode.Bounds.Y);

                                    DrawInsertLine(e.Graphics, _lineBeginPoint.X, _lineBeginPoint.Y, CurrentNode.Bounds.Width);
                                    break;
                                }
                            ///鼠标在目标节点之后
                            case DragDropResultType.After:
                                {
                                    _lineBeginPoint = new Point(mouseNode.Bounds.X - 20, mouseNode.Bounds.Y + mouseNode.Bounds.Height);
                                    _lineEndPoint = new Point(mouseNode.Bounds.X + _InsertLineWidth, mouseNode.Bounds.Y + mouseNode.Bounds.Height);

                                    DrawInsertLine(e.Graphics, _lineBeginPoint.X, _lineBeginPoint.Y, CurrentNode.Bounds.Width);
                                    break;
                                }
                        }

                        ///只有在线画完后才将当前值存储起来
                        _dropResultType = dropResultType;
                        _dropResultNode = mouseNode;
                    }
                }
            }

            base.OnPaint(e);
        }
Beispiel #3
0
 public DragDropResult(TreeNodePro[] dragdropNodes, TreeNodePro dropNode, DragDropResultType dropResultType)
 {
     _dragdropNodes  = dragdropNodes;
     _dropPutNode    = dropNode;
     _dropResultType = dropResultType;
 }