Je ces morceaux de code:app.config pas mise à jour quand j'utiliser configmanager
string theme = ConfigurationManager.AppSettings["Theme"];
private void ChangeTheme(string Name)
{
if(Name=="Light")
{
Form1.ActiveForm.BackColor = System.Drawing.Color.White;
Form.ActiveForm.ForeColor = System.Drawing.Color.Black;
}
if (Name == "Dark")
{
Form1.ActiveForm.BackColor = System.Drawing.Color.Black;
Form.ActiveForm.ForeColor = System.Drawing.Color.DarkOrange;
}
Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfg.AppSettings.Settings["Theme"].Value = Name;
cfg.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
Mon app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Volume" value="7"/>
<add key="Keyval" value="X"/>
<add key="Theme" value="Light"/>
</appSettings>
</configuration>
En fait, lorsque j'appuie sur les boutons radio permettent de modifier le thème et envoie la chaîne à changetheme(), mais elle ne se met pas à jour dans app.config.
Copie possible de [Comment modifier mes clés App.exe.config au moment de l'exécution?] (Http://stackoverflow.com/questions/5468342/how-to-modify-my-app-exe-config-keys- at-runtime) – Igor
Copie possible de http://stackoverflow.com/questions/11149556/app-config-change-value –
Pourquoi n'utilisez-vous pas un ['Settings.settings'] (https://msdn.microsoft .com/fr-fr/library/0zszyc6e (v = vs.110) .aspx)? –