我有一个名为“KeyboardInput”的Keys数组。如何将它存储在“设置”中,然后将它们作为单独的键读出,如下所示:
for (int i = 0; i < KeyboardInput.Length; i++)
{
KeyboardInput[i] = (Keys)Enum.Parse(typeof(Keys), {{ Properties.Settings.Default.Keys[i]?? }});
}
Keys[] KeyboardInput = { Keys.A, Keys.S, Keys.N, Keys.M, Keys.H, Keys.F, Keys.T, Keys.G, Keys.W, Keys.Q, Keys.Z, Keys.X, Keys.Right, Keys.Left, Keys.Up, Keys.Down };
答案 0 :(得分:2)
令人惊讶的是,顶部Related question的答案似乎有效。添加设置后,右键单击Solution Explorer中的Settings.settings,Open With ...任何文本编辑器,然后更改类型:
[TestMethod]
public void MethodName14() {
var topList = new List<string>() {"AB", "DC", "ZG"}; // ordered by highest rank
var currentList = new List<string> {"ZG", "DC"};
var actual = ReturnTop(currentList, topList);
Assert.Equal("DC", actual); // because DC is in index 2 and ZG is in index 3
}
private string ReturnTop(List<string> currentList, List<string> topList) {
string result = null;
int index = 0;
foreach (var current in currentList) {
var lookupedCurrentIndex = topList.FindIndex(a => a == current);
if (index == 0) {
result = topList[index];
index = lookupedCurrentIndex;
} else {
if (lookupedCurrentIndex < index) {
index = lookupedCurrentIndex;
result = topList[index];
}
}
}
return result;
}
这也将更新 <Setting Name="Keys" Type="System.Windows.Forms.Keys[]" Scope="User">
文件,然后您可以像这样使用它:
Settings.Designer.cs