user1706184
user1706184

Reputation: 203

Keyboard event propagation in winforms

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?

Upvotes: 6

Views: 2353

Answers (2)

Alex
Alex

Reputation: 7838

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

Upvotes: 5

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

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

Upvotes: 1

Related Questions