Hi Dbooksta,
Thanks for your feedback!
Sorry, do you mean that you reset the focus after Navigate() method and it
works in your scenario? However, based on my test, this does not work on my
side, below is my testing code snippet:
void timer1_Tick(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://www.google.com");
this.textBox1.Focus();
this.timer1.Stop();
}
I recommend you give it a recheck. Anyway, if it works on your side, you
may go with it.
Regarding your further question, I am not sure if I understand it
completely. If you invoked Navigate() method and switch to another
application what is the problem you are encounterring? Thanks for clarify.
Normally, I think you may hook Form.Activated event and reset the focus
into the original focused control, like this:
private void Form1_Activated(object sender, EventArgs e)
{
this.textBox1.Focus();
}
Then whenever the user switch back to your application, the Activated event
handler will reset the focus as your need.
Finally, based on my research, not all web page you are accessing will
steal the focus, it is the javascript/jscript Element.focus() function that
causes the focus stealing behavior. If you view the source code of
www.google.com, you will find the following line in it:
function sf(){document.f.q.focus();}
Any web page does not call the focus internally will not steal the focus.
So I do not think there is any way to prevent the WebBrowser control from
stealing the focus, it is the javascript/Jscript code that steals the
focus. This behavior is by design. If you are curious, below is call stack
I captured with windbg for this stealing focus:
0013b84c 4a570824 USER32!NtUserSetFocus
0013b858 4a5ce628 mshtml!CDoc::TakeFocus+0x2a
0013b880 4a63fc0b mshtml!CElement::BecomeCurrent+0x167
0013b8b4 4a63fb72 mshtml!CElement::focusHelper+0xcc
0013b8c0 4a587c85 mshtml!CElement::focus+0x1d
0013b8cc 4a5d7477 mshtml!Method_void_void+0x17
0013b94c 4a57fae8 mshtml!CBase::ContextInvokeEx+0x462
0013b97c 4a575413 mshtml!CElement::ContextInvokeEx+0x72
0013b9b0 76fa5295 mshtml!CElement::ContextThunk_InvokeEx+0x44
0013b9e8 76fa5208 jscript!IDispatchExInvokeEx2+0xa9
0013ba20 76fa5323 jscript!IDispatchExInvokeEx+0x56
0013ba90 76fa577b jscript!InvokeDispatchEx+0x78
0013bad8 76fa57c6 jscript!VAR::InvokeByName+0x1c1
0013bb18 76fa4ab0 jscript!VAR::InvokeDispName+0x43
0013bb3c 76fa5a14 jscript!VAR::InvokeByDispID+0xfb
0013bd30 76fa46d8 jscript!CScriptRuntime::Run+0x195b
0013bdf4 76fa506e jscript!ScrFncObj::Call+0x69
0013be6c 76fa5f6a jscript!CSession::Execute+0xb8
0013bf6c 76fa672f jscript!NameTbl::InvokeDef+0x183
0013c040 76fa5295 jscript!NameTbl::InvokeEx+0xd2
Hope this helps. Also, please feel free to feedback any concern or
questions. Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.