WebBrowser 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 WebBrowser 類別的新執行個體。
public:
WebBrowser();
public WebBrowser ();
Public Sub New ()
例外狀況
會在 Internet Explorer 內裝載 WebBrowser 控制項。
範例
下列程式碼範例示範如何使用這個成員。
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 。 若要將它巡覽至初始檔,請設定 Url 屬性。