No matter how hard I try, I can't get the WebBrowser control to truely gain focus. Even after using WebBrowser1.Focus () in my program, when I run my program the WebBrowser control doesn't really get focus until I click on it with the mouse. How do I know this Well, the arrow keys don't work to scroll the web page, nor do PageUp or PageDown, until I click on the WebBrowser control with the mouse. Same goes for moving through the links with the TAB key.
Since SP1 for Visual Basic 2005 didn't change things, is there a way I can work around this problem, short of clicking on the control with the mouse

Bug with WebBrowser control and focus. Any workarounds?
shinoy
Duane Haas
shine46055
Is it posible you and nobugs are looking at different issues Have you tried WebBrowser.focus and webbrowser.select They work for me. Also have you tried looking at you tab indexes Set the webbrowser to zero.
Ross Watson
Protected Overrides Function IsInputKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
'--- Make form navigation keys act like input keys when the focus is on the web browser
If ReferenceEquals(Me.ActiveControl, Me.WebBrowser1) Then
If keyData = Keys.Up Or keyData = Keys.Down Or keyData = Keys.Left Or keyData = Keys.Right Then Return True
If keyData = Keys.PageDown Or keyData = Keys.PageUp Then Return True
If keyData = Keys.Tab Then Return True
End If
Return MyBase.IsInputKey(keyData)
End Function
rsacristanp
I have the same problem. I have a large sophisticated project. This is the last known glitch in the entire project. Also, it's quite possible this has been introduced by SP1. At any rate.....
I have a webbrowser control used as an editor. There is a text box control below the webbrowser control for document titles which has a press event. the last thing I do in the keypress event is webrowser.Focus
This does work. I've tried timer events 50 ms after the keypress to set the focus. That doesn't work.
I've set focus to the HTMLDocument contained by the webbrowser.
This is the last bug/annoyance in a really large and complex problem and it's driving me crazy.
Ekta
&#169&#59; Ţĩмό Şąļσмāĸ
Like I said I've tried many ways including yours. Same result. But thanks anyway.
Some details: My WB loads web-page on form load so I try to gain focus on WebBrowser1_DocumentCompleted event. WB TabIndex is 0 and .focus () or/and .select() have no effect.
P.S> Of course maybe some other elements (TextBoxes, Buttons etc.) causing that strange behaviour, but we're still there, where we were...
robinjam