private void treeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
 {
     if (treeView.SelectedNode?.Tag?.GetType() == typeof(TOKLeaf))
     {
         TOKLeaf leaf = (TOKLeaf)treeView.SelectedNode.Tag;
         leaf.Text = String.Copy(textView.Text);
     }
 }
        private void addLeafToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView.SelectedNode.Tag?.GetType() != typeof(TOKLeaf))
            {
                TOKLeaf   leaf      = new TOKLeaf();
                TOKBranch tokParent = (TOKBranch)treeView.SelectedNode.Tag;
                tokParent.Nodes.Add(leaf);

                TreeNode treeNode = makeTreeNode(leaf);
                treeView.SelectedNode.Nodes.Add(treeNode);
                treeView.SelectedNode = treeNode;
            }
        }
 private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (treeView.SelectedNode?.Tag?.GetType() == typeof(TOKLeaf))
     {
         TOKLeaf leaf = (TOKLeaf)treeView.SelectedNode.Tag;
         textView.Text      = String.Copy(leaf.Text);
         textView.Enabled   = true;
         textView.BackColor = SystemColors.Window;
     }
     else
     {
         textView.Text      = "";
         textView.Enabled   = false;
         textView.BackColor = SystemColors.ControlDark;
     }
 }
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDlg = new SaveFileDialog
            {
                CheckPathExists = true,
                Filter          = "Tree Of Knowledge files (*.tok)|*.tok",
                DefaultExt      = "tok",
                FilterIndex     = 1
            };

            if (saveDlg.ShowDialog() == DialogResult.OK)
            {
                if (treeView.SelectedNode?.Tag?.GetType() == typeof(TOKLeaf))
                {
                    TOKLeaf leaf = (TOKLeaf)treeView.SelectedNode.Tag;
                    leaf.Text = String.Copy(textView.Text);
                }

                _tree.SaveAs(saveDlg.FileName);
            }
        }