Ejemplo n.º 1
0
        private void TreeView_DragOver(object sender, DragEventArgs e)
        {
            TreeNode targetCmd = TreeView.GetNodeAt(TreeView.PointToClient(Cursor.Position));
            TreeNode movingCmd = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");

            if (targetCmd == null)
            {
                TreeView.SelectedNode = null;
            }
            else if (targetCmd != movingCmd)
            {
                MovingCmdPosition movingCmdPosition = GetMovingCmdPositionOnTheTargetCmd(targetCmd, TreeView.PointToClient(Cursor.Position).Y);

                if (movingNodePositionBackup != movingCmdPosition)
                {
                    TreeView.Refresh();   // Node를 drag 할 때 화면이 깜박이는 것을 방지하기 위해서 node의 위치가 MovingCmdPosition에 준해서 바뀔 때에만 Refresh 한다.
                    movingNodePositionBackup = movingCmdPosition;
                    TreeView.SelectedNode    = targetCmd;
                }

                if (movingCmdPosition == MovingCmdPosition.MIDDLE)
                {
                    if (targetCmd.Nodes.Count > 0)
                    {
                        tmrNodeOver.Start();
                    }
                    else
                    {
                        tmrNodeOver.Stop();
                        DrawAddToFolderPlaceholder(targetCmd);
                    }
                }
                else
                {
                    tmrNodeOver.Stop();
                    DrawPlaceholder(targetCmd, movingCmdPosition);
                }
            }
        }
Ejemplo n.º 2
0
        private void DrawPlaceholder(TreeNode NodeOver, MovingCmdPosition placeHolderPosition)
        {
            Graphics g = TreeView.CreateGraphics();

            int NodeOverImageWidth = TreeView.ImageList.Images[NodeOver.ImageKey].Size.Width + 8;
            int LeftPos            = NodeOver.Bounds.Left - NodeOverImageWidth;
            int RightPos           = TreeView.Width - 4;
            int yPos = 0;

            if (placeHolderPosition == MovingCmdPosition.UPPER)
            {
                yPos = NodeOver.Bounds.Top;
            }
            else if (placeHolderPosition == MovingCmdPosition.LOWER)
            {
                yPos = NodeOver.Bounds.Bottom;
            }

            Point[] LeftTriangle = new Point[5] {
                new Point(LeftPos, yPos - 4),
                new Point(LeftPos, yPos + 4),
                new Point(LeftPos + 4, yPos),
                new Point(LeftPos + 4, yPos - 1),
                new Point(LeftPos, yPos - 5)
            };

            Point[] RightTriangle = new Point[5] {
                new Point(RightPos, yPos - 4),
                new Point(RightPos, yPos + 4),
                new Point(RightPos - 4, yPos),
                new Point(RightPos - 4, yPos - 1),
                new Point(RightPos, yPos - 5)
            };

            g.FillPolygon(System.Drawing.Brushes.White, LeftTriangle);
            g.FillPolygon(System.Drawing.Brushes.White, RightTriangle);
            g.DrawLine(new System.Drawing.Pen(Color.White, 2), new Point(LeftPos, yPos), new Point(RightPos, yPos));
        }
Ejemplo n.º 3
0
        private void InsertCmd(TreeView targetTree, TreeNode targetCmd, TreeNode insertCmd, MovingCmdPosition insertNodePosition)
        {
            if (targetCmd == null)
            {
                TreeView.Nodes.Add(targetCmd);
            }
            else
            {
                TreeNodeCollection targetParentCmd = (targetCmd.Parent == null) ? targetTree.Nodes : targetCmd.Parent.Nodes;

                switch (insertNodePosition)
                {
                case MovingCmdPosition.UPPER:
                    targetParentCmd.Insert(targetCmd.Index, insertCmd);
                    break;

                case MovingCmdPosition.MIDDLE:
                case MovingCmdPosition.OUTSIDE:
                    targetCmd.Nodes.Add(insertCmd);
                    break;

                case MovingCmdPosition.LOWER:
                    targetParentCmd.Insert(targetCmd.Index + 1, insertCmd);
                    break;
                }
            }
        }