ListView KeyUp Error for the Control Key

好久不见. 提交于 2019-12-29 02:07:08

问题


ListView.KeyDown <Ctrl> event shows the following:

e   KeyData = LButton | ShiftKey | Control
    base    {KeyData = LButton | ShiftKey | Control}
        Alt false   bool
        Control true    bool
        Handled false   bool
        KeyCode LButton | ShiftKey
        KeyData LButton | ShiftKey | Control
        KeyValue    17
        Modifiers   
        Shift   false   bool
        SuppressKeyPress    false   bool

I don't like the fact that the <ShiftKey> is showing up but the Control key is showing up. On ListView.KeyUp <Ctrl> event shows the following:

-       e   {KeyData = LButton | ShiftKey}
+       base    {KeyData = LButton | ShiftKey}
        Alt false   bool
        Control false   bool
        Handled false   bool
        KeyCode LButton | ShiftKey
        KeyData LButton | ShiftKey
        KeyValue    17
        Modifiers   None
        Shift   false   bool
        SuppressKeyPress    false

What gives it's weird. Look over the web to see if there are any examples of this error but could find nothing. I have tried setting the KeyPreview to true on the hosting form to no avail.

Any input is welcome.


回答1:


There's no error here, you simply pressed and released the Ctrl key. The debugger just isn't very good at converting the Keys enum to a string. It is confuzzled by that enum having the [Flags] attribute so it tries to map the individual bits in the value to a Key.

So KeyDown = (Keys.Control | Keys.ControlKey) = 0x20011. Which the debugger mangles to
0x20000 = Control
0x00010 = ShiftKey
0x00001 = LButton.

And Keyup = (Keys.ControlKey) = 0x00011. Which the debugger mangles to
0x00010 = ShiftKey
0x00001 = LButton.

Or in other words, ignore what the debugger tells you.



来源:https://stackoverflow.com/questions/19323579/listview-keyup-error-for-the-control-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!