2012-06-20 78 views
1

我正試圖在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); 
    } 

負載後,看來,我保存不成功。我的方法有錯嗎?

回答

2

如果它是一個標誌枚舉,你需要對它進行不同的設置。

例如:

VisibilitySwitchesSaves |= VisibilitySwitchesFlags.ReferenceLinesChecked;