开发者

WinForms Web Browser control forcing refocus?

I'm trying to automate a web process where I need to click a button repeatedly. When my code "clicks" that button (an HtmlElement obtained from the WebBrowser control I have on my form) then it brings focus back to my application, more specifically the WebBrowser control. I wish to better automate this process so that the user can do other things while the process is going on, but that can't happen if the window is unminimizing itself because it开发者_如何学Go's attaining focus.

The code associated with the clicking is:

HtmlElement button = Recruiter.Document.GetElementById("recruit_link");
button.InvokeMember("click");

I've also tried button.RaiseEvent("onclick") and am getting the exact same results, with focus problems and all.

I've also tried hiding the form, but when the InvokeMember/RaiseEvent method is called, whatever I was working on loses focus but since the form is not visible then the focus seems to go nowhere.

The only non-default thing about the webbrowser is it's URI being set to my page and ScriptErrorsSuppressed being set to True.


Why do You need to click this button? It's sending some form? If yes, you can use WebClient and simulate sending form without graphic interface.

Basicly almost anything significant requires connection to website using Get Post or multipart/post so WebClient will be perfect. You can simply get the site wich is this button on and parse it to get what clicking it do. And then simulate your own action.


In IE7 or higher you can implement IProtectFocus on the webbrowser site and deny the focus change. You would be much better off if you use the raw ActiveX or its wrappers that support this kind of customization, e.g. csexwb. If you have to use the winform webbrowser control, you need to create your own webbrowser site.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜