Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyUp(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                if (this._selectedNode != null)
                {
                    this.SelectedNode = this._selectedNode;
                }

                if (this._previousNode != null)
                {
                    this._previousNode.BackColor = SystemColors.HighlightText;
                    this._previousNode.ForeColor = SystemColors.ControlText;
                }

                this.Cursor            = Cursors.Default;
                this._formDrag.Visible = false;

                // Call cancel event
                if (this.DragCancel != null)
                {
                    CustomDragItemEventArgs ea = new CustomDragItemEventArgs();
                    foreach (TreeNode node in this.SelectedNodes)
                    {
                        ea.Nodes.Add(node);
                    }

                    this.DragCancel(this, ea);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDragLeave(EventArgs e)
        {
            if (this._selectedNode != null)
            {
                this.SelectedNode = this._selectedNode;
            }

            if (this._previousNode != null)
            {
                this._previousNode.BackColor = this._dragOverNodeBackColor;
                this._previousNode.ForeColor = this._dragOverNodeForeColor;
            }

            this._formDrag.Visible = false;
            this.Cursor            = Cursors.Default;

            // Call cancel event
            if (this.DragCancel != null)
            {
                CustomDragItemEventArgs ea = new CustomDragItemEventArgs();

                foreach (TreeNode node in this.SelectedNodes)
                {
                    ea.Nodes.Add(node);
                }

                this.DragCancel(this, ea);
            }
        }
Exemplo n.º 3
0
        private void tvUIMap_DragStart(object sender, CustomDragItemEventArgs e)
        {
            if ((e == null) || (e.Nodes == null))
            {
                return;
            }

            // cannot drag root node
            foreach (TreeNode node in e.Nodes)
            {
                if (node == tvUIMap.TopNode)
                {
                    tvUIMap.AllowDrop = false;
                    return;
                }
            }

            tvUIMap.AllowDrop = true;
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnItemDrag(System.Windows.Forms.ItemDragEventArgs e)
        {
            // If the user drags a node and the node being dragged is NOT
            // selected, then clear the active selection, select the
            // node being dragged and drag it. Otherwise if the node being
            // dragged is selected, drag the entire selection.
            try
            {
                TreeNode node = e.Item as TreeNode;

                if (node != null)
                {
                    if (!m_SelectedNodes.Contains(node))
                    {
                        SelectSingleNode(node);
                        ToggleNode(node, true);
                    }
                }

                base.OnItemDrag(e);
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }

            // DragDropTreeView
            this._selectedNode = (TreeNode)e.Item;

            // Call dragstart event
            if (this.DragStart != null)
            {
                CustomDragItemEventArgs ea = new CustomDragItemEventArgs();

                foreach (TreeNode node in this.SelectedNodes)
                {
                    ea.Nodes.Add(node);
                }
                ea.UIMapFile = this.UIMapFile;

                this.DragStart(this, ea);
            }
            // Change any previous node back
            if (this._previousNode != null)
            {
                this._previousNode.BackColor = SystemColors.HighlightText;
                this._previousNode.ForeColor = SystemColors.ControlText;
            }

            // Move the form with the icon/label on it
            // A better width measurement algo for the form is needed here

            int width = this._selectedNode.Text.Length * (int)this._formDrag.labelText.Font.Size;

            if (this._selectedNode.Text.Length < 5)
            {
                width += 20;
            }

            this._formDrag.Size = new Size(width, this._formDrag.Height);

            this._formDrag.labelText.Size = new Size(width, this._formDrag.labelText.Size.Height);
            this._formDrag.labelText.Text = this._selectedNode.Text;

            // Start drag drop
            DragData dragData = new DragData();

            dragData.UIMapFile = this.UIMapFile;
            foreach (TreeNode node in this.SelectedNodes)
            {
                dragData.Nodes.Add(node);
            }

            this.DoDragDrop(dragData, _dragMode);
        }