Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

c# - ListView KeyUp Error for the Control Key

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...