首页 数据库 mysql教程 Use C# to access Microsoft Web Browser component programmati

Use C# to access Microsoft Web Browser component programmati

Jun 07, 2016 pm 03:50 PM
access microsoft use web

C# 使用微软网页浏览器控件 译文见:http://blog.csdn.net/Felomeng/archive/2007/05/17/1613495.aspx Summary: This walkthrough demonstrates how to use the Microsoft Web browser control and the Microsoft Document Object Model (DOM) to programmat

C#使用微软网页浏览器控件

译文见:http://blog.csdn.net/Felomeng/archive/2007/05/17/1613495.aspx

Summary: This walkthrough demonstrates how to use the Microsoft Web browser control and the Microsoft Document Object Model (DOM) to programmatically access the elements of any Web page. (3 pages)

To access the DOM programmatically, you import both the Web browser component and references to the methods, properties, and events of the DOM into your C# project. You direct the Web browser to a URL by calling its Navigate method, and you must then wait for the documentation complete event. You obtain the document by casting the Web browser Document property to an IHTMLDocument2 interface object. You can query this object for its collections, such as its link or image collections, which are returned as IHTMLElementCollection objects.

In this walkthrough, you will use the Web browser and DOM to obtain and display all anchors found in a Web page.

To access the DOM programmatically

  1. Create a new Visual C# Windows Application project named DOM.

    The form name defaults to Form1.

  2. In Solution Explorer, right-click the References folder and select Add Reference.

    The Add Reference dialog box opens.

  3. Click on the .NET tab and double-click the component named Microsoft.mshtml.
  4. Click OK.

    References to the methods, events, and properties of the Microsoft DOM are added to the project.

  5. Open the Toolbox, right-click any tool, and choose Customize Toolbox.

    The Customize Toolbox dialog box opens.

  6. Click on the COM Components tab and check Microsoft Web Browser.

    The Web browser control labeled Explorer is added to the Toolbox components.

  7. Select the Explorer component and click the open form.

    A Web browser component named axWebBrowser1 is added to the form.

  8. Add a TextBox component above the browser component and a ListBox component below it, accepting the default names of textBox1 and listBox1.
  9. Add a Button component to the right of listBox1. Change the Text property to "Submit," and accept the default name of button1.

    The resulting form should look similar to the following screen shot:

    Use C# to access Microsoft Web Browser component programmati 

  10. Double-click on button1.

    The button1_Click method is added to the project.

  11. Replace the body of the button1_Click method with the following bold code:
    private void button1_Click(object sender, System.EventArgs e)
    {
    <code><strong>   object Zero = 0;</strong></code>
    <code><strong>   object EmptyString = "";</strong></code>
    <code><strong>   <span>axWebBrowser1</span>.Navigate(textBox1.Text,</strong></code>
    <code><strong>   ref Zero, ref EmptyString, ref EmptyString, ref EmptyString);</strong></code>
    }
    登录后复制
  12. Return to the form designer, select the browser component, and click the Events icon in the Properties window.

    A list of Web browser events appears.

  13. Double-click the Document Complete event.

    The axWebBrowser1_DocumentComplete event handler is added to the project.

  14. Add the following bold line of code to the beginning of the file Form1.cs:
    using System.Data;
    <strong>using mshtml;</strong>
    登录后复制
  15. Replace the body of the axWebBrowser1_DocumentComplete event handler with the following code:
    private void <span>axWebBrowser1</span>_DocumentComplete(
       object sender, 
       AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
    {
    <code><strong>   IHTMLDocument2 HTMLDocument = </strong></code>
    <code><strong>      (IHTMLDocument2) <span>axWebBrowser1</span>.Document;</strong></code>
    <code><strong>   IHTMLElementCollection links = HTMLDocument.links;</strong></code>
    
    <code><strong>   listBox1.Items.Clear();</strong></code>
    
    <code><strong>   foreach (HTMLAnchorElementClass el in links)</strong></code>
    <code><strong>   {</strong></code>
    <code><strong>      listBox1.Items.Add(el.outerHTML);</strong></code>
    <code><strong>   }</strong></code>
    }
    登录后复制
  16. Press F5 to build and run the project.

    The Form1 application appears.

  17. Type a URL—such as www.msn.com—into the text box and click Submit.

    The Web page is displayed in the browser, and a list of its anchors appears in the list box, as shown in the following screen shot.

    Use C# to access Microsoft Web Browser component programmati 

For more information, see the following topics in the MSDN Library:

  • Dynamic HTML (http://msdn.microsoft.com/library/en-us/iisref/html/psdk/asp/eadg39v0.asp)
  • IHTMLDocument2 interface (http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/document2/document2.asp)


 

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Windows11怎么禁用后台应用程序_Windows11禁用后台应用教程 Windows11怎么禁用后台应用程序_Windows11禁用后台应用教程 May 07, 2024 pm 04:20 PM

1、在Windows11中打开设置。您可以使用Win+I快捷方式或任何其他方法。2、转到应用程序部分,然后单击应用程序和功能。3、查找要阻止在后台运行的应用程序。单击三点按钮并选择高级选项。4、找到【后台应用程序权限】部分并选择所需的值。默认情况下,Windows11设置电源优化模式。它允许Windows管理应用程序在后台的工作方式。例如,一旦启用省电模式以保留电池,系统将自动关闭所有应用程序。5、选择【从不】可防止应用程序在后台运行。请注意,如果您注意到程序不向您发送通知、无法更新数据等,您可

deepseek怎么转换pdf deepseek怎么转换pdf Feb 19, 2025 pm 05:24 PM

DeepSeek 无法直接将文件转换为 PDF。根据文件类型,可以使用不同方法:常见文档(Word、Excel、PowerPoint):使用微软 Office、LibreOffice 等软件导出为 PDF。图片:使用图片查看器或图像处理软件保存为 PDF。网页:使用浏览器“打印成 PDF”功能或专用的网页转 PDF 工具。不常见格式:找到合适的转换器,将其转换为 PDF。选择合适的工具并根据实际情况制定方案至关重要。

无法允许访问 iPhone 中的摄像头和麦克风 无法允许访问 iPhone 中的摄像头和麦克风 Apr 23, 2024 am 11:13 AM

您在尝试使用应用程序时是否收到“无法允许访问摄像头和麦克风”?通常,您可以在需要提供的基础上向特定对象授予摄像头和麦克风权限。但是,如果您拒绝权限,摄像头和麦克风将无法工作,而是显示此错误消息。解决这个问题是非常基本的,你可以在一两分钟内完成。修复1–提供相机、麦克风权限您可以直接在设置中提供必要的摄像头和麦克风权限。步骤1–转到“设置”选项卡。步骤2–打开“隐私与安全”面板。步骤3–在那里打开“相机”权限。步骤4–在里面,您将找到已请求手机相机权限的应用程序列表。步骤5–打开指定应用的“相机”

java里面的dao是什么意思 java里面的dao是什么意思 Apr 21, 2024 am 02:08 AM

Java 中的 DAO(数据访问对象)用于分离应用程序代码和持久层,其优点包括:分离:与应用程序逻辑独立,便于对其进行修改。封装:隐藏数据库访问细节,简化与数据库的交互。可扩展性:可轻松扩展以支持新数据库或持久性技术。通过 DAO,应用程序可以调用方法来执行数据库操作,如创建、读取、更新和删除实体,无需直接处理数据库细节。

field在java中是什么意思 field在java中是什么意思 Apr 25, 2024 pm 10:18 PM

在Java中,"field"是类或接口中的数据成员,用于存储数据或状态。field的属性包括:类型(可为任何Java数据类型)、访问权限、static(属于类而非实例)、final(不可变)和transient(不序列化)。field用于存储类或接口的状态信息,例如存储对象数据和维护对象状态。

Java反射机制如何修改类的行为? Java反射机制如何修改类的行为? May 03, 2024 pm 06:15 PM

Java反射机制允许程序动态修改类的行为,无需修改源代码。通过Class对象操作类,可以通过newInstance()创建实例,修改私有字段值,调用私有方法等。但应谨慎使用反射,因为它可能会导致意外的行为和安全问题,并有性能开销。

vue中iframe跨域的方法 vue中iframe跨域的方法 May 02, 2024 pm 10:48 PM

在 Vue 中解决 iframe 跨域问题的方法:CORS:启用后端服务器中的 CORS 支持,在 Vue 中使用 XMLHttpRequest 或 fetch API 发送 CORS 请求。JSONP:使用后端服务器中的 JSONP 端点,在 Vue 中动态加载 JSONP 脚本。代理服务器:设置代理服务器转发请求,在 Vue 中使用第三方库(如 axios)发送请求并设置代理服务器 URL。

内存条长什么样 内存条长什么样 Apr 21, 2024 pm 01:01 PM

电脑内存条长什么样这张是显卡和内存条在电脑里的总览。电脑的独立显卡是插在显卡插槽上的,带个风扇,内存条在电脑主板的内存条卡槽里边,绿色长方体形状。笔记本内存条和台式机内存条是不一样的,而且两者不能通用。外观区别1:台式机内存,细长,长度为13-14厘米。2:笔记本内存,较短,约五厘米左右。内存是电脑中的桥梁,负责处理器与硬盘、主板、显卡等硬件之间的数据交换。途中画红圈的地方是内存条,在CPU风扇旁边,插在内存条上。看,电脑记忆棒长这样。用螺丝刀打开台式电脑的盖子,途中的红圈就是内存条。内存条是什

See all articles