Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当 ContextMenuStrip 打开时,例如,选择了一个选项Copy- 如果用户按下C- Copy。
Copy
C
如何防止这种情况?
如果设置KeyPressEventArgs.Handled字段不起作用,您可能需要捕获PreviewKeyDown事件并将事件更改为不是输入键 ( PreviewKeyDownEventArgs.IsInputKey = false) 以防止它被视为常规 KeyDown/KeyUp/KeyPress。
KeyPressEventArgs.Handled
PreviewKeyDown
PreviewKeyDownEventArgs.IsInputKey = false
有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.previewkeydown(v=vs.110).aspx。
注意:您还必须将所有 KeyPress 处理代码移动到 PreviewKeyDown,因为当您将 IsInputKey 设置为 false 时,您将停止获取 KeyPress 事件。