Search code examples
c#winformsregistryread-write

Saving the TextBox Values in Registry


I need some guidance in reading/writing/saving the values in Registry.I am new to this concept of saving things in registry

I have a Winform where i have to read/write to a App.config file and change the username and password using a winform.In my winform i have 2 textboxes and when i enter values and hit submit it changes the values in app.config.I somehow did that and no issues.

Now I need to send what ever values I have entered in the Textboxes to registry and save them thr and I should also be able to read them.

How shoud I do that ?


Solution

  • Here is a quick code:

    private void button1_Click(object sender, EventArgs e)
    {
        Microsoft.Win32.RegistryKey exampleRegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("ExampleTest");
        exampleRegistryKey.SetValue("Name", textBox1.Text);
        exampleRegistryKey.Close();
    }
    

    Now if you run regedit and must see under HKEY_CURRENT_USER\ExampleTest