• 通过键盘方向键控制TreeView节点的移动


    本文转载:http://dengzebo.blog.163.com/blog/static/18867406201032141932204/

    View Code
         #region "控制树节点移动,向左右下上"
            /// <summary>
            
    /// 通过Ctrl+键盘移动选定的树节点
            
    /// </summary>
            
    /// <param name="TreeView1">要编辑的TreeView控件</param>
            
    /// <param name="eKeys">The <see cref="System.Windows.Forms.KeyEventArgs"/>KeyEventArgs为按键事件提供数据</param>
            public void MoveSelectNode(TreeView TreeView1, KeyEventArgs eKeys)
            {
                try
                {
                    if (TreeView1.SelectedNode == null)
                    {
                        return;
                    }

                    try
                    {
                        if (eKeys.KeyCode == Keys.Up && eKeys.Control == true)
                        {
                            TreeNode TN = new TreeNode();
                            TN = TreeView1.SelectedNode;
                            TreeNode TempNode = (TreeNode)TreeView1.SelectedNode.Clone();
                            if (TreeView1.SelectedNode.PrevNode == null)
                            {
                                return;

                            }
                            if (TN.Parent == null)
                            {
                                TreeView1.Nodes.Insert(TN.Index - 1, TempNode);
                            }
                            else
                            {
                                TN.Parent.Nodes.Insert(TN.Index - 1, TempNode);
                            }

                            TreeView1.SelectedNode.Remove();
                            TreeView1.SelectedNode = TempNode;
                        }

                        else if (eKeys.KeyCode == Keys.Down && eKeys.Control == true)
                        {
                            TreeNode TN = new TreeNode();
                            TN = TreeView1.SelectedNode;
                            TreeNode TempNode = (TreeNode)TreeView1.SelectedNode.Clone();
                            if (TreeView1.SelectedNode.NextNode == null)
                            {
                                return;
                            }
                            if (TN.Parent == null)
                            {
                                TreeView1.Nodes.Insert(TN.Index + 2, TempNode);
                            }
                            else
                            {
                                TN.Parent.Nodes.Insert(TN.Index + 2, TempNode);
                            }
                            TreeView1.SelectedNode.Remove();
                            TreeView1.SelectedNode = TempNode;
                        }
                        else if (eKeys.KeyCode == Keys.Left && eKeys.Control == true)
                        {
                            TreeNode TN = new TreeNode();
                            TN = TreeView1.SelectedNode;
                            TreeNode TempNode = (TreeNode)TreeView1.SelectedNode.Clone();
                            if (TreeView1.SelectedNode.Parent == null)
                            {
                                return;
                            }
                            else
                            {
                                if (TreeView1.SelectedNode.Parent.Parent == null)
                                {
                                    TreeView1.Nodes.Add(TempNode);
                                }

                                else
                                {
                                    TN.Parent.Parent.Nodes.Add(TempNode);
                                }
                            }
                            TN.Remove();
                            TreeView1.SelectedNode = TempNode;
                        }
                        else if (eKeys.KeyCode == Keys.Right && eKeys.Control == true)
                        {
                            TreeNode TN = new TreeNode();
                            TN = TreeView1.SelectedNode;
                            TreeNode TempNode = (TreeNode)TreeView1.SelectedNode.Clone();
                            if (TreeView1.SelectedNode.NextNode == null)
                            {
                                return;
                            }
                            TN.NextNode.Nodes.Insert(0, TempNode);
                            TN.Remove();
                            TreeView1.SelectedNode = TempNode;
                        }
                    }
                    catch
                    {

                    }

                }
                catch
                { }

            }

            #endregion
  • 相关阅读:
    【Dubbo 源码解析】08_Dubbo与Spring结合
    【Dubbo 源码解析】07_Dubbo 重试机制
    【Dubbo 源码解析】06_Dubbo 服务调用
    【Dubbo 源码解析】05_Dubbo 服务发现&引用
    【Dubbo 源码解析】04_Dubbo 服务注册&暴露
    【Dubbo 源码解析】03_Dubbo Protocol&Filter
    【Dubbo 源码解析】02_Dubbo SPI
    Hadoop(十五)MapReduce程序实例
    Hadoop(十四)MapReduce原理分析
    Hadoop(十三)分析MapReduce程序
  • 原文地址:https://www.cnblogs.com/51net/p/2447452.html
Copyright © 2020-2023  润新知