本文整理汇总了C#中Keys.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Keys.ToArray方法的具体用法?C# Keys.ToArray怎么用?C# Keys.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Keys
的用法示例。
在下文中一共展示了Keys.ToArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetKeys
public HResult SetKeys(INiCommandBarButton button, Keys[] keys)
{
try
{
if (button == null)
throw new ArgumentNullException("button");
if (keys == null)
throw new ArgumentNullException("keys");
foreach (var key in keys)
{
if (!ShortcutKeysUtil.IsValid(key))
throw new ArgumentException(String.Format("{0} is not a valid shortcut", key));
}
var id = button.Id;
List<Keys> currentKeys;
if (!_mappingsByButton.TryGetValue(id, out currentKeys))
{
currentKeys = new List<Keys>();
_mappingsByButton.Add(id, currentKeys);
}
// Remove the button from keys that are not set anymore.
foreach (var key in currentKeys)
{
if (!keys.Contains(key))
{
List<Guid> buttons;
if (_mappingsByKeys.TryGetValue(key, out buttons))
{
bool removed = buttons.Remove(id);
Debug.Assert(removed);
}
else
{
Debug.Fail("Expected key to appear in mapping");
}
}
}
// Add the button to new keys.
foreach (var key in keys)
{
if (!currentKeys.Contains(key))
{
List<Guid> buttons;
if (!_mappingsByKeys.TryGetValue(key, out buttons))
{
buttons = new List<Guid>();
_mappingsByKeys.Add(key, buttons);
}
buttons.Add(id);
}
}
// Save the new key bindings.
currentKeys.Clear();
currentKeys.AddRange(keys);
// Update the new mappings with the new keys.
if (AreSameKeys(_keyboardMappingManager._initialKeys[id], keys))
Mappings.Remove(id);
else
Mappings[id] = keys.ToArray();
return HResult.OK;
}
catch (Exception ex)
{
return ErrorUtil.GetHResult(ex);
}
}