WebBrowser.DocumentCompleted イベント

定義

WebBrowser コントロールでドキュメントの読み込みが終了したときに発生します。

public:
 event System::Windows::Forms::WebBrowserDocumentCompletedEventHandler ^ DocumentCompleted;
public event System.Windows.Forms.WebBrowserDocumentCompletedEventHandler DocumentCompleted;
public event System.Windows.Forms.WebBrowserDocumentCompletedEventHandler? DocumentCompleted;
member this.DocumentCompleted : System.Windows.Forms.WebBrowserDocumentCompletedEventHandler 
Public Custom Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler 
Public Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler 

イベントの種類

次のコード例では、このイベントを使用して、ドキュメントが完全に読み込まれた後に文書を印刷する方法を示します。

private void PrintHelpPage()
{
    // Create a WebBrowser instance. 
    WebBrowser webBrowserForPrinting = new WebBrowser();

    // Add an event handler that prints the document after it loads.
    webBrowserForPrinting.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(PrintDocument);

    // Set the Url property to load the document.
    webBrowserForPrinting.Url = new Uri(@"\\myshare\help.html");
}

private void PrintDocument(object sender,
    WebBrowserDocumentCompletedEventArgs e)
{
    // Print the document now that it is fully loaded.
    ((WebBrowser)sender).Print();

    // Dispose the WebBrowser now that the task is complete. 
    ((WebBrowser)sender).Dispose();
}
Private Sub PrintHelpPage()

    ' Create a WebBrowser instance. 
    Dim webBrowserForPrinting As New WebBrowser()

    ' Add an event handler that prints the document after it loads.
    AddHandler webBrowserForPrinting.DocumentCompleted, New _
        WebBrowserDocumentCompletedEventHandler(AddressOf PrintDocument)

    ' Set the Url property to load the document.
    webBrowserForPrinting.Url = New Uri("\\myshare\help.html")

End Sub

Private Sub PrintDocument(ByVal sender As Object, _
    ByVal e As WebBrowserDocumentCompletedEventArgs)

    Dim webBrowserForPrinting As WebBrowser = CType(sender, WebBrowser)

    ' Print the document now that it is fully loaded.
    webBrowserForPrinting.Print()
    MessageBox.Show("print")

    ' Dispose the WebBrowser now that the task is complete. 
    webBrowserForPrinting.Dispose()

End Sub

注釈

コントロールは WebBrowser 、次のいずれかのプロパティが設定されるか、メソッドが呼び出されるたびに、新しいドキュメントに移動します。

新しいドキュメントの DocumentCompleted 読み込みが完了したときに通知を受け取るイベントを処理します。 イベントがDocumentCompleted発生すると、新しいドキュメントが完全に読み込まれます。つまり、、DocumentText、または DocumentStream プロパティを使用してその内容にDocumentアクセスできます。

ナビゲーションが開始する前に通知を受信するには、 イベントを処理します Navigating 。 このイベントを処理すると、ユーザーがフォームに完全に入力していない場合など、特定の条件が満たされていない場合にナビゲーションを取り消すことができます。 コントロールがナビゲーションを Navigated 終了し、新しい場所でドキュメントの WebBrowser 読み込みを開始したときに通知を受け取るイベントを処理します。

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。

適用対象

こちらもご覧ください