Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用注册表重新填充文本框_C#_Visual Studio 2010_Registry - Fatal编程技术网

C# 如何使用注册表重新填充文本框

C# 如何使用注册表重新填充文本框,c#,visual-studio-2010,registry,C#,Visual Studio 2010,Registry,在程序停止使用注册表后,如何用以前的文本重新填充文本框 我读过多篇文章,如: 到目前为止,我什么都没有,因为没有任何结果,我得到的只是错误D: public string Read(string KeyName) { RegistryKey rk = baseRegistryKey ; RegistryKey sk1 = rk.OpenSubKey(subKey); if ( sk1 == null )

在程序停止使用注册表后,如何用以前的文本重新填充文本框

我读过多篇文章,如:

到目前为止,我什么都没有,因为没有任何结果,我得到的只是错误D:

     public string Read(string KeyName)
     { 
         RegistryKey rk = baseRegistryKey ;
         RegistryKey sk1 = rk.OpenSubKey(subKey);
         if ( sk1 == null )
              return null;
         else
         {
             try 
             {
                  return (string)sk1.GetValue(KeyName.ToUpper());
             }    
             catch (Exception ex)
             {

             }
         }
     }

表示baseRegistryKey和subKey不存在。它说RegistryKey不存在。如何修复?

我几天前也遇到了同样的问题,不要使用那些瞄准具,它们都很糟糕

您的代码有几处错误:

  • baseRegistryKey和subKey需要设置为某种参数
  • 如果RegisterKey不起作用,那么您可能没有使用Microsoft.Win32执行
  • 我用来解决这个问题的代码是:

    public WindowsConsoleForm1();
        try
        {
            InitializeComponent();
            textBox1.Text = Application.UserAppDataRegistry.GetValue("example").ToString();
        }
        catch { }
    
  • 然后在您有的地方,例如:
    textbox1.text=Path.GetDirectoryName(saveFileDialoge1.FileName)
    ,在它下面发布
    Application.UserAppDataRegistry.SetValue(“示例”,textbox1.text)


    • 几天前我也遇到了同样的问题,不要使用那些瞄准具,它们都很糟糕

      您的代码有几处错误:

      • baseRegistryKey和subKey需要设置为某种参数
      • 如果RegisterKey不起作用,那么您可能没有使用Microsoft.Win32执行
      • 我用来解决这个问题的代码是:

        public WindowsConsoleForm1();
            try
            {
                InitializeComponent();
                textBox1.Text = Application.UserAppDataRegistry.GetValue("example").ToString();
            }
            catch { }
        
      • 然后在您有的地方,例如:
        textbox1.text=Path.GetDirectoryName(saveFileDialoge1.FileName)
        ,在它下面发布
        Application.UserAppDataRegistry.SetValue(“示例”,textbox1.text)


      请向我们展示您正在使用的代码(而不是您阅读过的文章的链接),并具体告诉我们您遇到了哪些错误。您还没有定义变量baseRegistryKey或subKey,我可以告诉您。所以它们不存在是有道理的。用于将数据写入注册表的代码在哪里?那里使用的注册表项是什么?@Gambit Ya有人已经说过了。谢谢你,现在一切都好了。请向我们展示你正在使用的代码(不是你读过的文章的链接),并具体告诉我们你遇到了什么错误。你还没有定义变量baseRegistryKey或subKey,我可以告诉你。所以它们不存在是有道理的。用于将数据写入注册表的代码在哪里?那里使用的注册表项是什么?@Gambit Ya有人已经说过了。不过谢谢你,现在一切都好了。