How to stop WebBrowser control getting automatic focus?

816 views
Skip to first unread message

coolvicki7

unread,
Mar 8, 2009, 3:53:16 AM3/8/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hello everyone,

In my vb .net application I load a web page through web browser
control automatically after few minutes. Now the problem is even if I
minimize the application, on auto refresh it shows up automatically
which is ofcourse annoying.

After researching on this, I now know that a piece of javascript on
this page is responsible for such behaviour.

How can I stop webbrowser control stealing the focus? Can anyone help
me in this?

Thanks

Leon

unread,
Mar 9, 2009, 8:55:14 AM3/9/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Heya!

I can't test my suggestion right now, but here it goes - perhaps if
you set the webbrowser control's Enabled property to false when you
minimize the app, or if you wrap it with a container control and set
the container's Enabled property to false, i guess it'll stop the
script from stealing the focus. Set it back to true after the form's
up and showing.

Hope it helps!

- Leon

coolvicki7

unread,
Mar 10, 2009, 2:04:40 AM3/10/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
thanks for your help but I already tried it without any success.

by some more research, I have found that by overriding wndproc and not
processing certain messages will do the trick. Though it does not seem
to be the best way but will somewhat work for few cases.
> > Thanks- Hide quoted text -
>
> - Show quoted text -

CallMeLaNN

unread,
Mar 14, 2009, 1:25:34 PM3/14/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
How about your trial?

Please share if you found the solution.

The focus is cause by the JavaScript from the web page when it load.

I think the idea is you should handle the JavaScript. I don't think so
there is a setting to disable focus.
But you can disable JavaScript setting for a moment in the code.
Remember that it is not WebBrowser setting, but IE setting.

Before that, try to disable it manually in IE setting then run your
WebBrowser to see the result.
Reply all
Reply to author
Forward
0 new messages