Click here to Skip to main content
15,849,829 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to Numericupdown value save in registry key in c#?


What I have tried:

in variable declaration :-
public string numaricupdownval = " ";


in main form load event:-
private void MainForm_Load(object sender, EventArgs e)
      {
          RegistryKey key = Registry.CurrentUser.OpenSubKey(@"360", true);
          {
              if (key != null)
              {
                 key.GetValue("numaricupdownval");
                 numaricupdownval = (string)key.GetValue("numaricupdown");
                 key.Close();
              }
          }
      }


in numaricvaluechange event :-
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
     {
         numaricupdownval = RectNumeric.Value.ToString();
         Microsoft.Win32.RegistryKey key;
         key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("360");
         key.SetValue("numaricupdown",numaricupdownval);
     }


this error occur :- value can't save in registry
Posted
Updated 15-Dec-22 2:44am
Comments
BillWoodruff 15-Dec-22 7:46am    
Describe your IDE and app context. Why use the Registry ? Why not use an app Setting ?

1 solution

Basically, don't.

The registry is not as easy to use as it was in the early days - because a lot of apps stored way too much in it, it became bloated, and that slowed down the whole OS.

So now, much of the registry is access protected, and for the HKEY_CURRENTUSER values you need your app to be running under your user at the very least (and still may not be able to access parts of it in future) and it may require your app to be elevated.

Avoid using the registry at all: access can only get tighter so it's more likley you app will fail in future.

Have a look here: Where should I store my data?[^] for some better ideas, or use a settings file instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900