gpt4 book ai didi

c# - Windows 窗体设置值不会在 session 之间保留

转载 作者:行者123 更新时间:2023-11-30 16:08:20 25 4
gpt4 key购买 nike

我正在开发一个 Windows 窗体应用程序,理想情况下它将在 session 之间存储库存值。

过去,我能够在 session 之间保存 Properties.Settings 值。但是,在我当前的应用程序中使用类似的代码我无法这样做。

这是我尝试保存值的代码片段:

    foreach (KeyValuePair<string, double> ingredient in inventoryDictionary)
{
var ingredientUnit = unitList[ingredient.Key];
lstInventory.Items.Add(item: string.Format(@"{0} {1} {2}", ingredient.Key, ingredient.Value, ingredientUnit));
settings[ingredient.Key] = ingredient.Value;
settings.Save();
}

值在事件 session 期间存储,但一旦表单关闭,值始终重置为默认值。

我的所有设置都列在“用户”范围下,并且“类型”如预期的那样为 double。此外,设置中的所有值默认设置为 0。

在此问题上的任何帮助将不胜感激。之前我已经能够在 session 之间保存值,但我不确定为什么此时它不起作用...

谢谢

最佳答案

尝试使用 Properties.Settings.Default

例子:

Properties.Settings.Default.myColor = Color.AliceBlue;

如果你想在 session 之间持久化它

Properties.Settings.Default.Save();

参见 The MSDN link here

关于c# - Windows 窗体设置值不会在 session 之间保留,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29584159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com