Ich habe diese Code-Teile:app.config nicht aktualisiert, wenn ich configmanager verwenden
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");
}
Mein 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>
Grundsätzlich, wenn ich die Radio-Buttons drücken wechselt er das Thema und sendet die Zeichenfolge an changetheme(), aber es wird nicht in der app.config aktualisiert.
Mögliche Duplikate von [Wie ändere ich meine App.exe.config Schlüssel zur Laufzeit?] (Http://StackOverflow.com/Questions/5468342/How-To-Modify-My-App-Exe-config-keys- zur Laufzeit) – Igor
Mögliches Duplikat von http://stackoverflow.com/questions/11149556/app-config-change-value –
Warum verwenden Sie kein ['Settings.settings'] (https://msdn.microsoft .com/de-de/library/0zszyc6e (v = vs.110) .aspx)? –