Esempio n. 1
0
        private void timer_Tick(object sender, EventArgs e)
        {
            // get node at mouse position
            Point    pt   = PointToClient(Control.MousePosition);
            TreeNode node = this.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.Refresh();
                    // show drag image
                    DragHelper.ImageList_DragShowNolock(true);
                }
            }
            // if mouse is near to the bottom, scroll down
            else if (pt.Y > this.Size.Height - 30)
            {
                if (node.NextVisibleNode != null)
                {
                    node = node.NextVisibleNode;

                    DragHelper.ImageList_DragShowNolock(false);
                    node.EnsureVisible();
                    this.Refresh();
                    DragHelper.ImageList_DragShowNolock(true);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 在将对象拖到控件的边界上发生。
        /// </summary>
        /// <param name="drgevent"></param>
        protected override void OnDragOver(DragEventArgs e)
        {
            // Compute drag position and move image
            Point formP = this.PointToClient(new Point(e.X, e.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(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.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;
            }

            base.OnDragOver(e);
        }