tags:

views:

103

answers:

1

I need to catch keypresses in my C# program that has a WebBrowser control in it.

I know how to do it if there isn't any controls on the form or if I use a textbox or similar but the WebBrowser control seems to handle all keypresses itself.

Is there any way to override the WebBrowser_KeyDown function?

+3  A: 

Set the KeyPreview property on the Form to True:

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx

Program.X
It didn't work when I used the WebBrowser control. Id did however work just fine when using a picture box.. Thanks anyway.
MrMe
Strange your way does work if I remove focus from my program and give it focus again. But if I do it again (focus something else and then my program again) it stops working... Strange, but at least something to work on. Thanks!
MrMe
I would say something other than your browser instance has focus.
kenny
There were a function called: webBrowser_PreviewKeyDown() that I didn't see before. That one seems to be able to catch key presses even when the web browser were out of focus.
MrMe