如何使用.NET WebBrowser对象 [英] How to use the .net webBrowser object

查看:185
本文介绍了如何使用.NET WebBrowser对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何一个知道一个教程使用System.Windows.Forms.WebBrowser对象?一看四周,但不能找到一个。在code我迄今为止是(非常复杂):

any one know of a tutorial for using the System.Windows.Forms.WebBrowser object? Had a look around but can't find one. The code I have so far is (the very complex):

System.Windows.Forms.WebBrowser b = new System.Windows.Forms.WebBrowser();
b.Navigate("http://www.google.co.uk");

,但它实际上并不导航的任何地方(iebUrl为空,b.Document为null等)

but it doesn't actually navigate anywhere (i.e. b.Url is null, b.Document is null etc)

感谢

推荐答案

这需要时间浏览器导航到一个页面。该导航()方法的没有的块,直到导航是完整的,这将冻结用户界面。该DocumentCompleted事件时,它的完成发射。你必须把你的code到事件处理该事件。

It takes time for the browser to navigate to a page. The Navigate() method does not block until the navigation is complete, that would freeze the user interface. The DocumentCompleted event is fired when it's done. You have to move your code into an event handler for that event.

另外一个要求是,在其上创建一个WB线程是一个美好的家园单线程的COM组件。它必须是STA和泵消息循环。控制台模式应用程序做的没有的满足这一要求,只有一个WinForms或WPF项目有这样的线程。检查<一href="http://stackoverflow.com/questions/4269800/c-webbrowser-control-in-a-new-thread/4271581#4271581">this回答一个解决方案,就是用控制台模式程序兼容。

An additional requirement is that the thread on which you create a WB is a happy home for single-threaded COM components. It must be STA and pump a message loop. A console mode app does not meet this requirement, only a Winforms or WPF project has such a thread. Check this answer for a solution that's compatible with console mode programs.

这篇关于如何使用.NET WebBrowser对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆