简体   繁体   中英

Save Settings in VB.Net or C#

How I can save the settings I want even after I close the program?

Let's say: If I have a Checkbox and I run the program. If I checked it I want to remain that way even when I reopen again the program. I hope you understand what I want.

I'm a newbie, so take me slow. Thank you.

I recommend using Application Settings Property Binding .

There are many options as mrunion mentioned in his good answer, but I think the most simple way in Windows Forms Application is using Application Settings Property Binding. To do so using designer:

  1. Select your CheckBox in design surface
  2. In properties window, at top, expand (ApplicationSettings) , open dropdown for Checked property and select (New...) at bottom of dropdown.
  3. Add your desired property with default value.
  4. Save settings in somewhere like Form_Closing event:

    • C#: Properties.Settings.Default.Save();
    • VB: My.Settings.Save()

(ApplicationSettings) in property window:

在此处输入图片说明

Expanded from above....

To persist settings between different program runs, you will have to store that data somewhere for the user. Assuming since you mentioned VB, I will also assume Windows as your target platform. The best options are the following:

  1. Use the registry to store the persistent data. There are plenty of tutorials on setting and retrieving registry variables.
  2. Use a configuration/INI file for your application. Again, plenty of tutorials exist for this option.
  3. Use a database. This is more advanced, but allows for the most flexibility of storing and retrieving data. I would suggest not using this method at first, and revisit it when you are ready to learn database design/querying/etc.

This should point you in the right direction.

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