WebBrowser学习

1. NavigateComplete2 事件

在一个窗口windows元素或者框架frameset元素,导航navigate到链接完成时触发
此事件替换 在 IE4.0 和 IE5 为兼容 IE3.0 继续使用的 NavigateComplete 和 FrameNavigateComplete 事件

2. Navigate方法
object.Navigate(url, [Flags], [TargetFrameName], [PostData], [Headers])
导航到被URL或者全路径文件标识的资源
IE6及以上,你可以在应用程序托管的WebBrowser控件写代码导航到同一个网域。否则,Navigate 和 Navigate2 被禁用
IE7, 可以指定 navOpenInNewTab 或者 navOpenInBackgroundTab 标记。若标签浏览禁用或不能创建,key选择其他导航方法,如 navOpenInNewWindow
https://msdn.microsoft.com/en-us/library/aa752093(v=vs.85).aspx

3. Navigate2方法
object.Navigate2(URL, Flags, TargetFrameName, PostData, Headers)
导航到一个或许不能用URL表示的地址,例如Windows Shell空间的实体指向 PIDL的指针 a pointer to an item identifier list (PIDL) for an entity in the Windows Shell namespace. 此方法扩展 Navigate 方法来允许Shell集成;但不会使 Navigate 过时. 原方法继续用于 URL 导航.
https://msdn.microsoft.com/en-us/library/aa752094(v=vs.85).aspx

3. WebBrowser.ProgressChanged 事件
当 WebBrowser 控件在下载一个导航到的文件过程更新信息后发生
你可以给这个事件使用一个 handler 来实现类似IE的导航进度条. 使用 WebBrowserProgressChangedEventArgs.CurrentProgress 属性 确定成功下载的字节数. 使用 WebBrowserProgressChangedEventArgs.MaximumProgress 属性确定可用的下载字节数.
https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.progresschanged(v=vs.110).aspx

4. IHTMLDocument2 接口
获取文档的信息,检查、修改文本中的HTML元素、文本
IHTMLDocument2 接口继承 IDispatch 接口,所以拥有他们的成员类型
每个Window 对象有一个响应文档对象(corresponding document object),可以通过调用 QueryIntrerface 方法中 IID_IHTMLDocument 或 IID_IHTMLDocument2 接口标识符获取. Windows 包含 HTML 文档集一般含有有效的文档对象; windows包含其他格式的文档集可能没有有效的文档对象.一般,在尝试获取一个不在当前window的Window的文档对象, 确保与window关联的资源文件是一个HTML 文档文件或者能被表示成 HTML 文档,比如,一个文本文件(text file).
此 interface 在代码中也被称为 IOmDocument2.
https://msdn.microsoft.com/en-us/library/aa752574(v=vs.85).aspx

I have a winform and a WebBrowser control and I am changing an option in select HTML control.

webBrowser1.Document
.GetElementsByTagName("select")[4]
.GetElementsByTagName("option")[13]
.SetAttribute("selected", "true");
Now it works and selects the required option, but it does not fire the onchange event. The select does not have an element id but it does have a class name.

I tried:
webBrowser1.Document
.GetElementsByTagName("select")[4]
.RaiseEvent("onchange");
and
webBrowser1.Document
.GetElementsByTagName("select")[4]
.GetElementsByTagName("option")[13]
.RaiseEvent("onchange");

I tried and sent a TAB key after selecting an option and it raised the onchange event.

webBrowser1.Document.GetElementsByTagName("select")[4].Focus();
webBrowser1.Document.GetElementsByTagName("select")[4]
.GetElementsByTagName("option")[13].SetAttribute("selected", "true");
SendKeys.Send("{TAB}");

原文地址:https://www.cnblogs.com/dennysong/p/5436374.html