Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the code you need:</p> <pre><code> If WB.ContainsFocus Then MsgBox("We have focus, disappearing...") WB.Document.Body.RemoveFocus() End If </code></pre> <p>Now, the question is, when to run that code. If you put it in the WebBrowser1_GotFocus event, you'll need to turn it on and off. Turn the code off if the user is interacting with the WB Control, and turn it back on when they are not and when you expect to be experiencing the problem you've mentioned.</p> <p>Of course, you could add another line to ensure a particular control/tab/panel etc gets focus after you remove focus from the body. Also, here are 3 other SO questions that have answers which may help you, but these will take you in directions different to the direction I've provided, probably due to the fact that the questions are not identical to yours, but are similar enough to be useful (not listed in order of preference).</p> <p><a href="https://stackoverflow.com/questions/1562619/prevent-webbrowser-control-from-stealing-focus">Prevent WebBrowser control from stealing focus?</a></p> <p><a href="https://stackoverflow.com/questions/8495857/webbrowser-steals-focus">Webbrowser steals focus</a></p> <p><a href="https://stackoverflow.com/questions/5312755/focusing-webbrowser-control-in-a-c-sharp-application">Focusing WebBrowser control in a C# application</a></p> <p>UPDATE: I just wanted to add, instead of the .Body.RemoveFocus() you could do this:</p> <pre><code>WB.Document.Body.Parent.RemoveFocus() </code></pre> <p>Which I prefer, since the .Document object didn't have an explicit .RemoveFocus method on the intellisense I was gettign in VS2012 RC. This is probably referring to the HTML tag (and not the .Document object) and since the <code>html</code> tag is the only parent to the <code>body</code> tag, it makes sense, and there is no "HTML" object directly available in the intellisense under object, since you can get it via other means, so it's just more convenient doing it this way.</p> <p>Cheers, and let me know if you need more info on anything.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload