在键盘的WinForms事件传播 [英] Keyboard event propagation in winforms
问题描述
我有一个用户控制。在用户控制,存在使用整个屏幕房地产(Dock.Fill)一个PictureBox。我想赶上键盘事件(例如,按Ctrl-V执行粘贴功能)。
I have a user control. Within the user control, there is a PictureBox that uses up the entire screen estate (Dock.Fill). I would like to catch keyboard events (e.g., Ctrl-V for implementing Paste functionality).
不过,该图片没有任何关键事件。将图片框(即用户控件)下的下一层获得KeyUp事件?如果我将KeyUp事件处理程序添加到用户控件,将这项工作?我知道WPF具有路由事件的解决方案。如何在世界上的WinForms的工作?
However, the PictureBox does not have any key events. Will the next layer under the PictureBox (i.e. the user control) get the KeyUp event? If I add my KeyUp event handler to the user control, will that work? I know that WPF has the solution of routed events. How does that work in winforms world?
推荐答案
您可以在形式接收事件。请参见 Form.KeyPreview 。
You can receive the event in the form. See Form.KeyPreview.
在此属性设置为true,窗体将接收所有的KeyPress,KeyDown和的KeyUp事件。窗体的事件处理程序处理完按键后,击键,然后分配给具有焦点
When this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. After the form's event handlers have completed processing the keystroke, the keystroke is then assigned to the control with focus
这篇关于在键盘的WinForms事件传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!