Beispiel #1
0
        /// <summary>
        /// Function to determine if this node is an ancestor of the parent node.
        /// </summary>
        /// <param name="parentNode">Parent node to evaluate for ancestry.</param>
        /// <returns>TRUE if the child is ancestor of parent, FALSE if not.</returns>
        public bool IsAncestorOf(TreeNodeEditor parentNode)
        {
            TreeNode node = Parent;

            // Walk up the chain.
            while (node != null)
            {
                if (node == parentNode)
                {
                    return(true);
                }

                node = node.Parent;
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Function to hide the rename box.
        /// </summary>
        /// <param name="canceled">TRUE if the edit was canceled, FALSE if not.</param>
        public void HideRenameBox(bool canceled)
        {
            if (_renameBox == null)
            {
                return;
            }

            var editNode = _editNode;

            _renameBox.KeyDown   -= _renameBox_KeyDown;
            _renameBox.LostFocus -= _renameBox_LostFocus;
            _renameBox.Visible    = false;
            _editNode             = null;

            var eventArgs = new NodeLabelEditEventArgs(editNode, canceled ? editNode.Text : _renameBox.Text);

            OnAfterLabelEdit(eventArgs);

            if (!eventArgs.CancelEdit)
            {
                editNode.Text = eventArgs.Label;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Function to show the rename text box.
        /// </summary>
        /// <param name="node">Node to edit.</param>
        public void ShowRenameBox(TreeNodeEditor node)
        {
            if (node == null)
            {
                return;
            }

            if (_renameBox == null)
            {
                _renameBox = new TextBox
                {
                    Name        = Name + "_EditBox",
                    Visible     = false,
                    BorderStyle = BorderStyle.None,
                    BackColor   = Color.White,
                    ForeColor   = Color.Black,
                    Height      = node.Bounds.Height,
                    AcceptsTab  = false,
                    Anchor      = AnchorStyles.Left | AnchorStyles.Right
                };
                Controls.Add(_renameBox);
            }

            // Wipe out the background.
            using (var g = CreateGraphics())
            {
                // Create graphics resources.
                if (_selectBrush == null)
                {
                    _selectBrush = new SolidBrush(DarkFormsRenderer.MenuHilightBackground);
                }

                g.FillRectangle(_selectBrush, new Rectangle(0, node.Bounds.Y, ClientSize.Width, node.Bounds.Height));
            }

            Point nodePosition = node.Bounds.Location;

            nodePosition.X += node.Level * 16 + 24;
            nodePosition.Y++;
            if (node.CollapsedImage != null)
            {
                nodePosition.X += node.CollapsedImage.Width + 2;
            }

            _renameBox.Location = nodePosition;
            _renameBox.Width    = ClientSize.Width - nodePosition.X;
            _renameBox.Text     = node.Text;

            var editArgs = new NodeLabelEditEventArgs(node, node.Text)
            {
                CancelEdit = false
            };

            OnBeforeLabelEdit(editArgs);

            if (editArgs.CancelEdit)
            {
                return;
            }

            _editNode = node;
            _editNode.Redraw();
            _renameBox.Visible = true;
            _renameBox.Focus();

            if (node.Text.Length > 0)
            {
                _renameBox.Select(0, node.Text.Length);
            }

            _renameBox.KeyDown   += _renameBox_KeyDown;
            _renameBox.LostFocus += _renameBox_LostFocus;
        }