I have a form and a sub-form, both with some controls that are bound to settings in app.config.
The sub-form has Save and Cancel buttons, and should the user click on Save, it will save the settings, if they click on Cancel, the form closes without saving.
When the main form closes (using FormClosing event) I also save the settings (for that form), but since the sub-form settings are in the same place, it saves those settings too.
But perhaps I have changed the sub-form controls, and then exited via Cancel – in this situation, these unwanted settings would also be saved when the main form exits.
So how should I handle this? Clearly, I could specifically reset the sub-form values when Cancel is pressed; but ideally I’d like to not have to keep updating this code each time I add or remove a settings-bound control.
I was wondering if there is a form-level reset or rollback option, so I can reset the state of the sub-form without having to manipulate individual controls manually?
Or perhaps I should maintain separate settings files for each form? I assume there is no reason why I couldn’t do this, but is there a better way?
The solution I have gone for is to separate out the different application/user/form settings into different .settings file (see: this question).
With greater granular control over my settings, I can Reload the settings related to this form (only) in the FormClosing event.