相关疑难解决方法(0)

在运行时创建新设置并在重新启动后读取

我想存储用户设置。它们是在运行时创建的,应在重新启动应用程序后读取。

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();对结果没有任何影响。我也尝试过类似这里描述的其他东西,但它们都不适合我。

c# settings winforms

5
推荐指数
1
解决办法
1199
查看次数

标签 统计

c# ×1

settings ×1

winforms ×1