0

I have 5 check boxes, I wish to be able to store whether or not the user has checked them or not in a settings file so that when they open the program they can find that file open it and the same checkboxes are selected.

I cannot for the life of me find anything that is helping me on this subject. Please refrain from simply linking me to an MSDN article because I have read every page about User Settings and Application Settings and I still do not understand.

If someone could please give me an example of how to do this it would really help me, Thank you

At the moment I am writing the TabIndex of each checkbox to a text file, when I chose to load the text file, my program reads the lines of text and extracts the TabIndex from which I test and base the chk.selected attribute on.

This feels like the wrong way to go about storing user settings

AdamWest
  • 29
  • 1
  • 9

1 Answers1

1

Go to your Project's Properties, open the Settings pane, and create a Settings-File. This file will be stored to Properties->Settings.Settings but you can edit it easyly from the Settings page of the properties.

Create a row Name it IsMyCheckbox1Checked, set it's type to Bool and the scope to user. If you want add a comment.

In your application you may now use this as follows:

Boolean b = Properties.Settings.Default.IsMyCheckbox1Checked; //Read the Setting
Properties.Settings.Default.UsMyCheckbox1Checked = Checkbox1.Checked; //Write the Setting
Properties.Settings.Default.Save(); // Persist the Setting to the user's appData-Folder

Hope this helps.

TGlatzer
  • 5,815
  • 2
  • 25
  • 46
  • Ermm, kind of, but when you say "create a settings file" do you mean a text document of type settings? – AdamWest Aug 24 '12 at 08:42
  • Basically I have a form with 5 checkboxes, when the user selects some of them and clicks "save" I want to be able to store the selected checkboxes in some form of settings file so that when they run the program again they can go "file...open...settings1" and the saved checkboxes are checked. Does this make sense? Ive asked so many people and I can't get the response Im looking for so maybe I don't ask correctly – AdamWest Aug 24 '12 at 08:47
  • You should use the settings file that Visual Studio provides for you. Right click on your Project, click Properties and then select Settings tab. You can add your settings in here (for example name it 'IsMyCheckbox1Checked', and set its type to boolean. Then you can use the code above. – sventevit Aug 24 '12 at 09:17
  • I thought you were referring to this. I looked into this alot but I couldn't see how to export the data to an external file as I'm requested to. At the moment I have a (very crude) system where I obtain the index of each checkbox and output that to a textfile along with the name of the checkbox that corresponds to it. This is working fine, but loading the data is difficult to an extent.. – AdamWest Aug 24 '12 at 10:44
  • Settings files will be in your application Directory for the application Settings and somewhere in %appData% for the user Settings. Save and load will be handled by .NET for you – TGlatzer Aug 24 '12 at 11:56