Use C# to access Microsoft Web Browser component programmati
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
- Create a new Visual C# Windows Application project named DOM.
The form name defaults to Form1.
- In Solution Explorer, right-click the References folder and select Add Reference.
The Add Reference dialog box opens.
- Click on the .NET tab and double-click the component named Microsoft.mshtml.
- Click OK.
References to the methods, events, and properties of the Microsoft DOM are added to the project.
- Open the Toolbox, right-click any tool, and choose Customize Toolbox.
The Customize Toolbox dialog box opens.
- Click on the COM Components tab and check Microsoft Web Browser.
The Web browser control labeled Explorer is added to the Toolbox components.
- Select the Explorer component and click the open form.
A Web browser component named axWebBrowser1 is added to the form.
- Add a TextBox component above the browser component and a ListBox component below it, accepting the default names of textBox1 and listBox1.
- 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:
- Double-click on button1.
The button1_Click method is added to the project.
- 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> }
ログイン後にコピー - 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.
- Double-click the Document Complete event.
The axWebBrowser1_DocumentComplete event handler is added to the project.
- Add the following bold line of code to the beginning of the file Form1.cs:
using System.Data; <strong>using mshtml;</strong>
ログイン後にコピー - 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> }
ログイン後にコピー - Press F5 to build and run the project.
The Form1 application appears.
- 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.
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)

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









1. Windows 11で設定を開きます。 Win+I ショートカットまたはその他の方法を使用できます。 2. 「アプリ」セクションに移動し、「アプリと機能」をクリックします。 3. バックグラウンドでの実行を禁止したいアプリケーションを見つけます。三点ボタンをクリックして、[詳細オプション] を選択します。 4. [バックグラウンド アプリケーションのアクセス許可] セクションを見つけて、目的の値を選択します。デフォルトでは、Windows 11 は電力最適化モードを設定します。これにより、Windows はアプリケーションがバックグラウンドでどのように動作するかを管理できるようになります。たとえば、バッテリーを節約するためにバッテリー セーバー モードを有効にすると、システムはすべてのアプリを自動的に終了します。 5. アプリケーションがバックグラウンドで実行されないようにするには、[なし] を選択します。プログラムが通知を送信していない、データの更新に失敗しているなどに気付いた場合は、次のことができることに注意してください。

DeepSeekはファイルを直接PDFに変換できません。ファイルの種類に応じて、異なる方法を使用できます。一般的なドキュメント(Word、Excel、PowerPoint):Microsoft Office、Libreoffice、その他のソフトウェアを使用してPDFとしてエクスポートします。画像:画像ビューアまたは画像処理ソフトウェアを使用してPDFとして保存します。 Webページ:ブラウザの「Print into PDF」関数を使用するか、PDFツールに専用のWebページを使用します。 UNCOMMONフォーマット:適切なコンバーターを見つけて、PDFに変換します。適切なツールを選択し、実際の状況に基づいて計画を作成することが重要です。

Java では、「フィールド」は、データまたは状態を格納するために使用されるクラスまたはインターフェイスのデータ メンバーです。フィールドのプロパティには、タイプ (任意の Java データ型)、アクセス権、静的 (インスタンスではなくクラスに属する)、最終 (不変)、および一時 (シリアル化されていない) が含まれます。フィールドは、オブジェクト データの保存やオブジェクトの状態の維持など、クラスまたはインターフェイスの状態情報を保存するために使用されます。

Oracle は、次の手順で dbf ファイルを読み取ることができます。外部テーブルを作成し、その dbf ファイルを参照し、データを Oracle テーブルにインポートします。

Java リフレクション メカニズムを使用すると、プログラムはソース コードを変更せずにクラスの動作を動的に変更できます。 Class オブジェクトを操作することで、newInstance() によるインスタンスの作成、プライベート フィールドの値の変更、プライベート メソッドの呼び出しなどが可能になります。ただし、リフレクションは予期しない動作やセキュリティ上の問題を引き起こす可能性があり、パフォーマンスのオーバーヘッドがあるため、注意して使用する必要があります。

Java 関数開発における一般的な例外の種類とその修復方法 Java 関数の開発中に、関数の正しい実行に影響を与えるさまざまな例外が発生する可能性があります。一般的な例外の種類とその修復方法は次のとおりです。 1. NullPointerException 説明: 初期化されていないオブジェクトにアクセスするとスローされます。修正: オブジェクトを使用する前に、オブジェクトが null でないことを確認してください。サンプル コード: try{Stringname=null;System.out.println(name.length());}catch(NullPointerExceptione){

Vue で iframe クロスドメインの問題を解決する方法: CORS: バックエンド サーバーで CORS サポートを有効にし、XMLHttpRequest またはフェッチ API を使用して Vue で CORS リクエストを送信します。 JSONP: バックエンド サーバーの JSONP エンドポイントを使用して、Vue に JSONP スクリプトを動的に読み込みます。プロキシ サーバー: リクエストを転送するためにプロキシ サーバーを設定し、Vue のサードパーティ ライブラリ (axios など) を使用してリクエストを送信し、プロキシ サーバー URL を設定します。

昨日、BotanixLabs は、Polychain Capital、Placeholder Capital などの参加を得て、総額 1,150 万米ドルの資金調達を完了したと発表しました。資金は、BTCL2Botanix に相当する分散型 EVM を構築するために使用されます。スパイダーチェーンは、EVM の使いやすさとビットコインのセキュリティを組み合わせています。 2023 年 11 月にテストネットが稼働して以来、アクティブなアドレスは 200,000 を超えています。 Odaily では、この記事で Botanix の特徴的なメカニズムとテストネットの相互作用プロセスを分析します。 Botanix 公式定義によると、Botanix はビットコイン上に構築された分散型チューリング完全 L2EVM であり、2 つのコア コンポーネントで構成されています: イーサリアム仮想マシン
