简体   繁体   中英

How do I save settings in C#

I am building a stand alone program so there are no external files for the program to access. What would be the best way to recall what the size of the window, and the location of a certain element inside the window were prior the the last shut down?

我可以使用.NET提供的设置来做到这一点,这很舒服: http : //msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx

Well, I think the options are two:

  • Also if you're not using external files you could store your settings in the auto-generated .config file;
  • Save the values in the registry;

For the first option look at MSDN , for the second try to look here .

EDIT: How to write into the registry:

RegistryKey currentUser = Registry.CurrentUser;
RegistryKey subKey = currentUser.CreateSubKey("MyTest", RegistryKeyPermissionCheck.ReadWriteSubTree);
subKey.SetValue("WindowHeight", 1024);
subKey.SetValue("WindowWidth", 1024);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM