我正在尝试在settings.cs文件中保存一系列布尔值。这是我目前的保存方法。
private void SaveConfiguration()
{
VisibilitySwitchesFlags VisibilitySwitchesSaves = 0;
if (_menu.TreeItemDictionary[VisibilityItems.ReferenceLines].Checked)
VisibilitySwitchesSaves = VisibilitySwitchesFlags.ReferenceLinesChecked;
if (_menu.TreeItemDictionary[VisibilityItems.ShowProfilePoints].Checked)
VisibilitySwitchesSaves = VisibilitySwitchesFlags.ShowProfilePointsChecked;
Settings.Default.VisibilityViewStates = (int)VisibilitySwitchesSaves;//convert to int
Settings.Default.Save();
}
这是我的Load方法:
private void LoadConfiguration()
{
VisibilitySwitchesFlags flags =(VisibilitySwitchesFlags)Settings.Default.VisibilityViewStates;
_menu.TreeItemDictionary[VisibilityItems.ReferenceLines].Checked = flags.HasFlag(VisibilitySwitchesFlags.ReferenceLinesChecked);
_menu.TreeItemDictionary[VisibilityItems.ShowProfilePoints].Checked = flags.HasFlag(VisibilitySwitchesFlags.ShowProfilePointsChecked);
}
加载后,我的保存似乎不成功。我的方法有误吗?
答案 0 :(得分:2)
如果它是一个标志枚举,你需要以不同的方式设置它。
例如:
VisibilitySwitchesSaves |= VisibilitySwitchesFlags.ReferenceLinesChecked;