有没有什么办法将允许我使用华廷的功能从我的网页浏览器的控制?只是我想用华廷与我的网页浏览器控制,我不希望我的应用程序打开一个新的窗口,我需要在我的Web浏览器控件。
Is there any way which would allow me to use watin's functionalities from my web browser control? simply i want to use watin with my web browser control i don't want my application to open a new window ,i need it in my web browser control.
如果您使用的是.NET WebBrowser控件,你可以使用下面的$ C $创建华廷的即
对象C:
If you are using .Net WebBrowser Control you can create WatiN's IE
object by using following code:
var ie = new IE(webBrowser.ActiveXInstance);
但是,如果你这样做,在你的的Form_Load
ActiveXInstance
将是无效的。如果你这样做,比如里面的某种 button_Click
的应用程序将挂起您使用后如。 ie.GoTo
。您需要启动新的线程和运行在那里。例如:
But if you do that inside your Form_Load
ActiveXInstance
will be null. And if you do that for example inside some kind of button_Click
the application will hang after you use eg. ie.GoTo
. You need to start new thread and operate there. For example:
private void Form1_Load(object sender, EventArgs e)
{
var t = new Thread(() =>
{
Settings.AutoStartDialogWatcher = false;
var ie = new IE(webBrowser1.ActiveXInstance);
ie.GoTo("http://www.google.com");
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
您需要禁用对话框观察者的自动启动,因为你不能使用内置的华廷对话框守望者。但随着黑客,你可以创建自己的基于原始 DialogWatcher
类的一点点。处理弹出窗口和创建新的Web浏览器控件也是可能的。
You need to disable auto start of dialog watcher, because you cannot use built in WatiN dialog watcher. But with a little bit of hacking you can create your own based on original DialogWatcher
class. Handling popups and creating new web browser controls are also possible.
上一篇:转换异步/等待到Task.ContinueWithTask、ContinueWith
下一篇:从外部的DoEvents WebBrowser控件获取的readyState控件、DoEvents、WebBrowser、readyState