我在通过C#控制IE时遇到了一些问题。 几乎所有东西都管理好了。 但我似乎无法将重点放在开放的探险家身上。 当我在VS 2010中它可以工作,但是当我直接运行exe文件时就不是这样了。
using SHDocVw;
.
<code>
.
InternetExplorer ie = new InternetExplorer();
IWebBrowserApp wb = (IWebBrowserApp)ie;
.
<code>
.
wb.Visible = true;
wb.Document.focus();
我的意思是wb.Document.focus();
会将重点放在IE上,但这不会起作用。
还试过eb.Document.focus();
有人有消化吗?
答案 0 :(得分:1)
将ie.Document转换为mshtml.HTMLDocument,然后设置焦点。
//Like so
InternetExplorer ie = new InternetExplorer();
((mshtml.HTMLDocument)ie.Document).focus();
答案 1 :(得分:0)
这是不可靠的。可靠的解决方案是使用API(我的发现:-)):
vb:
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdSHow As Long) As Long
Dim ie As SHDocVw.InternetExplorerClass
ie = New SHDocVw.InternetExplorer : Application.DoEvents()
'the reliable focus:
ShowWindow(ie.HWND, 0) : ShowWindow(ie.HWND, 1)