# Region move a node with the keyboard up/down key and ctrl key
/// <Summary>
/// Move the node by pressing the left and right buttons on the keyboard and pressing the ctrl key.
/// Idea: Copy two selected nodes. 1. To remember the node location selected for the first time, 2. during the migration process, a specified position will be inserted,
/// Then remove the selected node
/// </Summary>
/// <Param name = "treeView"> treeview </param>
/// <Param name = "keys"> keyboard buttons </param>
Public void MoveTreeNodeByKeyWord (TreeView treeView, KeyEventArgs keys)
{
If (treeView. SelectedNode! = Null)
{
// Move up
If (keys. KeyCode = Keys. Up & keys. Control = true)
{
TreeNode tn = new TreeNode ();
Tn = treeView. SelectedNode;
TreeNode tempnode = (TreeNode) treeView. SelectedNode. Clone ();
If (treeView. SelectedNode. PrevNode = null)
{
Return;
}
If (tn. Parent = null)
{
TreeView. Nodes. Insert (tn. Index-1, tempnode );
}
Else
{
Tn. Parent. Nodes. Insert (tn. Index-1, tempnode );
}
TreeView. SelectedNode. Remove ();
TreeView. SelectedNode = tempnode;
}
// Move down
Else if (keys. KeyCode = Keys. Down & keys. Control = true)
{
TreeNode tn = new TreeNode ();
Tn = treeView. SelectedNode;
TreeNode tempnode = (TreeNode) treeView. SelectedNode. Clone ();
If (treeView. SelectedNode. NextNode = null)
{
Return;
}
If (tn. Parent = null)
{
TreeView. Nodes. Insert (tn. Index + 2, tempnode );
}
Else
{
Tn. Parent. Nodes. Insert (tn. Index + 2, tempnode );
}
TreeView. SelectedNode. Remove ();
TreeView. SelectedNode = tempnode;
}
// Left
Else if (keys. KeyCode = Keys. Left & keys. Control = true)
{
TreeNode tn = new TreeNode ();
Tn = treeView. SelectedNode;
TreeNode tempnode = (TreeNode) treeView. SelectedNode. Clone ();
If (treeView. SelectedNode. Parent = null)
{
Return;
}
If (treeView. SelectedNode. Parent. Parent = null)
{
TreeView. Nodes. Add (tempnode );
}
Else
{
Tn. Parent. Parent. Nodes. Add (tempnode );
}
Tn. Remove ();
// TreeView. SelectedNode. Remove ();
TreeView. SelectedNode = tempnode;
}
// Right
Else if (keys. KeyCode = Keys. Right & keys. Control = true)
{
TreeNode tn = new TreeNode ();
Tn = treeView. SelectedNode;
TreeNode tempnode = (TreeNode) treeView. SelectedNode. Clone ();
If (treeView. SelectedNode. NextNode = null)
{
Return;
}
TreeView. SelectedNode. NextNode. Nodes. Insert (0, tempnode );
Tn. Remove ();
TreeView. SelectedNode = tempnode;
}
}
}
# Endregion