Keyboard event propagation in winforms

房东的猫 提交于 2019-12-01 16:10:37

问题


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).

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?


回答1:


You can receive the event in the form. See Form.KeyPreview.

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




回答2:


You can use MouseUp, MouseEnter, MouseDown or MouseHover ....

Link about Mouse Down : http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousedown.aspx

Link : http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.aspx



来源:https://stackoverflow.com/questions/12639673/keyboard-event-propagation-in-winforms

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