First, create a data model of all settings. This should be a set of some data classes, not related to functionality. This model should be central to you settings system. I mean, if the functional unit of the applications needs to "decide" how to proceed, it should ask the model, not UI control. The UI controls should be populated from the instance of the model, and the model should be instantiated based on the state of controls. The functionality should not be altered directly, only through the data model.
On next step, you need to develop a persistence for the instanced of the model. To do so, I would advice using
Data Contracts. Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^].
This method is most comprehensive and at the same time, easiest to use and non-intrusive. It means, you do not need to modify your data model types in order to comply. You only add some Data Contract related attributes to the types of the model and some of their members (only those essential for the contract).
Please see my past answers where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[
^],
Creating property files...[
^],
deseralize a json string array[
^].
After this step, you will be able to store the model is some XML file (only one) or a stream and load it back exactly as it was in memory. If does not have to be a file on the file system, it could be in a network or resource string, anything.
That brings us to a last step: presets. I would advise to create the presets in the resources embedded in your assembly. First of all, prepare the presets. For this purpose, set some options manually and save each preset as a regular XML file using the persistence created on the previous step. You can have a file open dialog, file save dialog and two corresponding menu options to store/load a preset by this time, after you have your persistence working. Now, it's a time to embed the presets.
You don't have to work with resources directly. Instead, create some *.resx resource in the assembly you want to keep the presets. In the resource windows, click on Add Resource, Add Existing File and just add the preset XML files you already prepared. The files will be copies to the project, added to the project and referenced from the resource file. All the preset files and a resource file will become a part of the source code, so don't remove them. At the same time, make sure you do not store the presets file twice: the procedure shown above will create copies, so, if the location of original files is different, the duplicates will appear, so make sure to delete original files; you only need files included in your project.
Now, finally: how to use the embedded resources? In case of XML files, this is way too simple. Look at the auto-generated VB file, found in the project tree with Solution Explorer as a child item under the node of the resource file. Look at this file in the editor: it will contain a static class with static properties of the string type, containing the context of your preset XML files. You will be able to recognize those properties because their name will be the same or close to the name of your source XML file. User these properties directly in your code to load a preset.
That's it.
—SA