Ejemplo n.º 1
0
        private void txtAddress_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)ConsoleKey.Enter)
            {
                try
                {
                    string        path          = txtAddress.Text.Trim();
                    List <string> pathDirection = path.Split('\\').ToList();
                    RegistryKey   basekey       = RegistryManager.GetBaseKeyByName(pathDirection[0]);
                    if (basekey == null)
                    {
                        throw new UserHandledException("آدرس وارد شده صحیح نمیباشد");
                    }
                    RegistryKey key = RegistryManager.GetRegistryKey(basekey, string.Join("\\", pathDirection.Skip(1)));
                    if (key == null)
                    {
                        throw new UserHandledException("آدرس وارد شده صحیح نمیباشد");
                    }

                    TreeNode[] treeNodesClone = new TreeNode[treeViewRegistery.Nodes.Count];
                    treeViewRegistery.Nodes.CopyTo(treeNodesClone, 0);
                    TreeNode node = treeNodesClone.Where(n => n.Text == pathDirection[0]).FirstOrDefault();
                    treeViewRegistery.SelectedNode = node;
                    BindNodesOnNode(treeViewRegistery.SelectedNode);
                    foreach (string dir in pathDirection.Skip(1))
                    {
                        treeNodesClone = new TreeNode[treeViewRegistery.SelectedNode.Nodes.Count];
                        treeViewRegistery.SelectedNode.Nodes.CopyTo(treeNodesClone, 0);
                        node = treeNodesClone.Where(n => n.Text == dir).FirstOrDefault();

                        treeViewRegistery.SelectedNode         = node;
                        treeViewRegistery.SelectedNode.Checked = true;
                        BindNodesOnNode(treeViewRegistery.SelectedNode);
                    }
                    treeViewRegistery.SelectedNode.Collapse(true);
                    treeViewRegistery.Focus();
                    Log($"Found Node :{treeViewRegistery.SelectedNode.FullPath}");
                }
                catch (UserHandledException ex)
                {
                    Debug.WriteLine("UserHandledException Error", ex);
                    MessageBox.Show(ex.Message, "اخطار", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }