I use the VSTO built-in settings file in order to save Windows- application settings.
I have a checkBox on my WinForm, whereas at form load I read its state (checked or unchecked) from the appropriate property in the settings file.
This works fine as long as I do not exit the application.
However, when I quit and then execute the application again- the settings are not saved from last execution and the checkBox state is not as the last preference.
I use "user" scope to save the settings.
On form load, extract the checkBox state from Settings.
private void MyFormLoad(object sender, EventArgs e)
{
//Find the appropriate property in the Settings file
System.Configuration.SettingsProperty property;
property = P_Settings.Settings.Default.Properties[checkBox.Name];
if (property != null)
checkBox.Checked = Convert.ToBoolean(property.DefaultValue);
}
On form close, Synchronize settings file with form status.
private void ButtonApplyClick(object sender, EventArgs e)
{
System.Configuration.SettingsProperty property;
property = P_Settings.Settings.Default.Properties[checkBox.Name];
property.DefaultValue = checkBox.Checked.ToString();
P_Settings.Settings.Default.Save();
}