Keys.D1 = LButton | ShiftKey |空间? [英] Keys.D1 = LButton | ShiftKey | Space?

查看:123
本文介绍了Keys.D1 = LButton | ShiftKey |空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写的通常运行良好的程序现在对Keys.D1感到震惊,其值是"LButton | ShiftKey | Space"

A program I've written that normally works well is now freaking out about Keys.D1 having a value of "LButton | ShiftKey | Space"

以下是该问题的屏幕抓图:

Here's a screen grab of the problem:

ModifierKeys是具有以下定义的枚举:

ModifierKeys is an enum with the following definition:

public enum ModifierKeys : uint
{
    Alt = 1,
    Control = 2,
    Shift = 4,
    Win = 8
}

这到底是怎么回事?没有其他对Keys.D1的引用.

What on earth is going on here? There are no other references to Keys.D1.

推荐答案

引用自键枚举:

警告
不要将此枚举中的值用于按位组合操作.枚举中的值不是互斥的.

Caution
Do not use the values in this enumeration for combined bitwise operations. The values in the enumeration are not mutually exclusive.

尽管System.Windows.Forms.Keys枚举具有[Flags]属性,但实际上可以安全地用作标志的唯一标志是:

Although the System.Windows.Forms.Keys enumeration has the [Flags] attribute, the only flags that can actually be safely used as flags are:

  • Keys.Shift
  • Keys.Ctrl
  • Keys.Alt
  • Keys.Shift
  • Keys.Ctrl
  • Keys.Alt

所有其余值都不是标志"枚举值.结果,一些不是标志"值的值的组合恰好巧合起来形成其他不是标志"值的值.

All the remaining values are not "flags" enumeration values. As a result, some combinations of values that are not "flags" values coincidentally happen to combine to form other values that are not "flags" values.

您看到的效果是Enum.ToString()运算符滥用 [Flags]属性来构造这样的组合.这是无害的,因为根据上面的文档,ShiftKeySpace键决不打算组合在一起.

The effect your are seeing is the Enum.ToString() operator misusing the [Flags] attribute to construct such combinations. This is harmless because the ShiftKey and the Space key are never intended to be combined, per the documentation above.

这篇关于Keys.D1 = LButton | ShiftKey |空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆