1

I want to have a save preference option in my WinForms application. The user chooses yes/no and has an option to save preference, upon which the yes/no will be remembered and a form for such a choice will not be popped upon further re running the application.

I read about going to setting and changing but how to do it for different users, since all of them would choose for diff options and I need to maintain that.

Simply using a boolean variable will not help since it will be single user specific. Any suggestions?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • 1
    One option is to save an `settings.ini` or `settings.xml` in the `Application.UserAppDataPath`, which will be something like: `C:\Users\\AppData\Roaming\\\` (but strip off the `` subfolder). `` and `` are defined in the project's Assembly Information. Another option is to save settings in the Registry in the Current User. – Loathing Jun 05 '21 at 21:24
  • Thanks for the reply , this seems possible too. I basically created a file at the client side with his/her preference and will read from that at run time. Updating this as an asnwer –  Jun 05 '21 at 22:47

3 Answers3

1

So since i didn't want a database , I am creating a file at the client side and saving the preference there. At run time , I will read from the file and upon that , will decide whether to send form or not .

1

(1) At event close main form, you call method/action save result. See How to save data when closing event happen in WinForms?

You can save it to XML file (or text file, SQL lite, SQL Server, etc), popular way is XML file(s).

Read XML file to get saved result before processing business logic in your WinForms application at Load form event or another event type at early stage of application start-up period.

(2) You also save result at previous period in config file https://stackoverflow.com/a/453230/3728901

Properties.Settings.Default["SomeProperty"] = "Some Value";
Properties.Settings.Default.Save(); // Saves settings in application configuration file
Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • Thank you ! I tried (2) and got a few errors will try the (1) suggested –  Jun 06 '21 at 03:11
0

you can use a Model and store use selected config into it then you should serilaize it and save on database for specific user when reRun the application you can get config and deserialize it to Model and use it

Sign
  • 113
  • 8
  • Thanks ,Seems a possible solution but since i am not maintaining User database, I didn't want to set up for this because of complexity and overhead , if there's another easier method within application. –  Jun 05 '21 at 22:45