WebBrowser クラスとは? わかりやすく解説

WebBrowser クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

ユーザーフォーム内で Web ページ移動できるようにします。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class WebBrowser
    Inherits WebBrowserBase
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class WebBrowser : WebBrowserBase
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class WebBrowser : public
 WebBrowserBase
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class WebBrowser extends WebBrowserBase
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class WebBrowser extends
 WebBrowserBase
解説解説

WebBrowser コントロール使用すると、ブラウザ表示できるドキュメント (Web ページなど) を Windows フォーム アプリケーションホストできます。たとえば WebBrowser コントロール使用してHTML ベースユーザー支援機能や Web ブラウズ機能アプリケーション統合できます。さらに WebBrowser コントロール使用して既存Web ベース コントロールWindows フォーム クライアント アプリケーション追加することもできます

メモ重要 :

WebBrowser は、リソースへの負荷大きコントロールです。コントロール使用終えたら、必ず Dispose メソッド呼び出しすべてのリソース確実に解放するようにしてくださいDispose メソッドは、イベントを結びつけたスレッドと同じスレッド呼び出す必要がありますイベント結びつけるスレッドは、常にメッセージ スレッドまたはユーザー インターフェイス (UI) スレッドいずれかになります

WebBrowser コントロールは、信頼性一部しか確認されていないコードでは使用できません。詳細については、「部分信頼コードからのライブラリ使用」を参照してください

WebBrowser コントロールには、ナビゲーションに関する複数プロパティメソッドイベントあります次に示すメンバ使用してコントロール特定の URL移動することや、ナビゲーション履歴リストの中を前後移動すること、および現在のユーザーホーム ページ検索ページ読み込むことができます

ナビゲーション失敗した場合問題を示すページ表示されます。これらのいずれかメンバ使用したナビゲーションにより、ナビゲーションさまざまな段階で Navigating イベント、Navigated イベント、および DocumentCompleted イベント発生します

これらのメンバや、Stop メソッドRefresh メソッドなどのメンバ利用してInternet Explorer似たユーザー インターフェイス コントロールアプリケーション実装できますWebBrowser コントロールフォーム表示しない場合でも、一部メンバ役立ちます。たとえば、Print メソッド使用すると、Web ページユーザー表示せずに最新Web ページ印刷できます

また WebBrowser コントロール使用すると、アプリケーション作成したコンテンツや、データベースまたはリソース ファイルから取得したコンテンツ表示できます。DocumentText プロパティまたは DocumentStream プロパティ使用すると、現在のドキュメント内容文字列またはデータ ストリームとして取得または設定できます

また、Document プロパティ使用して Web ページコンテンツ操作することもできます。このプロパティには、現在のページHTML ドキュメント オブジェクト モデル (DOM: Document Object Model) へのマネージ アクセス提供する HtmlDocument オブジェクト格納されています。このプロパティを ObjectForScripting プロパティ組み合わせて使用しアプリケーションコードWeb ページダイナミック HTML (DHTML) コードとの双方向通信実装することで、Web ベースコントロールWindows フォーム コントロール1 つユーザー インターフェイス統合できますDocument プロパティ使用してアプリケーションからスクリプト コードメソッド呼び出すことができますスクリプト コードにより、window.external オブジェクトを介してアプリケーションアクセスできます。このオブジェクトホスト アクセス用に提供される組み込み DOM オブジェクトであり、ObjectForScripting プロパティ指定されオブジェクト割り当てられます。

Windows Mobile for Pocket PCWindows Mobile for SmartphoneWindows CE プラットフォームメモ : .NET Compact Framework アプリケーションWebBrowser機能をすべて利用するには、Pocket PC および SmartphoneWindows Mobile Version 5.0 ソフトウェアが必要です。詳細については、「方法 : .NET Compact FrameworkWebBrowser コントロール使用する」を参照してください

使用例使用例

WebBrowser コントロール使用するアドレス バー実装する方法次のコード例示します。この例では、webBrowser1 という名前の WebBrowser コントロールTextBoxAddress という名前の TextBox コントロール、および ButtonGo という名前の Button コントロールフォーム含まれていることを前提としています。テキスト ボックスURL入力しEnter キーを押すか [移動] ボタンクリックすると、WebBrowser コントロールが、指定されURL移動しますハイパーリンククリックして移動した場合テキスト ボックス自動的に更新され現在の URL表示されます。

コード全体については、「方法 : Windows フォーム アプリケーションWeb ブラウザ機能追加する」を参照してください

' Navigates to the URL in the address box when 
' the ENTER key is pressed while the ToolStripTextBox has focus.
Private Sub toolStripTextBox1_KeyDown( _
    ByVal sender As Object,
 ByVal e As KeyEventArgs) _
    Handles toolStripTextBox1.KeyDown

    If (e.KeyCode = Keys.Enter) Then
        Navigate(toolStripTextBox1.Text)
    End If

End Sub

' Navigates to the URL in the address box when 
' the Go button is clicked.
Private Sub goButton_Click( _
    ByVal sender As Object,
 ByVal e As EventArgs) _
    Handles goButton.Click

    Navigate(toolStripTextBox1.Text)

End Sub

' Navigates to the given URL if it is valid.
Private Sub Navigate(ByVal
 address As String)

    If String.IsNullOrEmpty(address) Then
 Return
    If address.Equals("about:blank")
 Then Return
    If Not address.StartsWith("http://")
 And _
        Not address.StartsWith("https://")
 Then
        address = "http://" & address
    End If

    Try
        webBrowser1.Navigate(New Uri(address))
    Catch ex As System.UriFormatException
        Return
    End Try

End Sub

' Updates the URL in TextBoxAddress upon navigation.
Private Sub webBrowser1_Navigated(ByVal
 sender As Object, _
    ByVal e As WebBrowserNavigatedEventArgs)
 _
    Handles webBrowser1.Navigated

    toolStripTextBox1.Text = webBrowser1.Url.ToString()

End Sub
// Navigates to the URL in the address box when 
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object
 sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        Navigate(toolStripTextBox1.Text);
    }
}

// Navigates to the URL in the address box when 
// the Go button is clicked.
private void goButton_Click(object sender,
 EventArgs e)
{
    Navigate(toolStripTextBox1.Text);
}

// Navigates to the given URL if it is valid.
private void Navigate(String address)
{
    if (String.IsNullOrEmpty(address)) return;
    if (address.Equals("about:blank")) return;
    if (!address.StartsWith("http://")
 &&
        !address.StartsWith("https://"))
    {
        address = "http://" + address;
    }
    try
    {
        webBrowser1.Navigate(new Uri(address));
    }
    catch (System.UriFormatException)
    {
        return;
    }
}

// Updates the URL in TextBoxAddress upon navigation.
private void webBrowser1_Navigated(object sender
,
    WebBrowserNavigatedEventArgs e)
{
    toolStripTextBox1.Text = webBrowser1.Url.ToString();
}
// Navigates to the URL in the address text box when 
// the ENTER key is pressed while the text box has focus.
void TextBoxAddress_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^
 e )
{
   if ( e->KeyCode == System::Windows::Forms::Keys::Enter &&
  !this->TextBoxAddress->Text->Equals( ""
 ) )
   {
      this->WebBrowser1->Navigate( this->TextBoxAddress->Text
 );
   }
}

// Navigates to the URL in the address text box when 
// the Go button is clicked.
void ButtonGo_Click( System::Object^ /*sender*/, System::EventArgs^
 /*e*/ )
{
   if (  !this->TextBoxAddress->Text->Equals(
 "" ) )
   {
      this->WebBrowser1->Navigate( this->TextBoxAddress->Text
 );
   }
}

// Updates the URL in TextBoxAddress upon navigation.
void WebBrowser1_Navigated( Object^ /*sender*/, System::Windows::Forms::WebBrowserNavigatedEventArgs^
 /*e*/ )
{
   this->TextBoxAddress->Text = this->WebBrowser1->Url->ToString();
}

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.WebBrowserBase
          System.Windows.Forms.WebBrowser
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からWebBrowser クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からWebBrowser クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からWebBrowser クラスを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「WebBrowser クラス」の関連用語

WebBrowser クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebBrowser クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS