我想存储用户设置。它们是在运行时创建的,应在重新启动应用程序后读取。
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
var property = new SettingsProperty("Testname");
property.DefaultValue = "TestValue";
Settings.Default.Properties.Add(property);
Settings.Default.Save();
}
Run Code Online (Sandbox Code Playgroud)
此时,设置已存储,我可以访问它。
重新启动应用程序后,新创建的设置就消失了:
public MainForm()
{
InitializeComponent();
foreach (SettingsProperty property in Settings.Default.Properties)
{
//Setting which was created on runtime before not existing
}
}
Run Code Online (Sandbox Code Playgroud)
尝试这件作品:Settings.Default.Reload();对结果没有任何影响。我也尝试过类似这里描述的其他东西,但它们都不适合我。