我的Winforms应用程序中有一个名为Settings.settings的“设置文件”,其中包含自定义方法等的部分类。有没有基于任意键加载/保存动态设置的方法?Winforms - 动态加载/保存设置
例如,我在我的应用程序中有一些ListViews,我想要保存/加载列宽;而不是为每个列表视图的每个列创建一个宽度设置,我想要一个简单的方法自动加载/保存宽度。
下面是我曾尝试保存方法的一个例子:
internal sealed partial class Settings
{
public void SetListViewColumnWidths(ListView listView)
{
String baseKey = listView.Name;
foreach (ColumnHeader h in listView.Columns)
{
String key = String.Format("{0}-{1}", baseKey, h.Index);
this[key] = h.Width;
}
}
}
当运行代码我得到错误“设置属性‘TestsListView-0’没有被发现。”有什么我失踪?