WebBrowser Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the WebBrowser class.
public:
WebBrowser();
public WebBrowser ();
Public Sub New ()
Exceptions
The WebBrowser control is hosted inside Internet Explorer.
Examples
The following code example demonstrates the use of this member.
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
Remarks
By default, the WebBrowser control is empty. To navigate it to an initial document, set the Url property.
Applies to
Colaborar conosco no GitHub
A fonte deste conteúdo pode ser encontrada no GitHub, onde você também pode criar e revisar problemas e solicitações de pull. Para obter mais informações, confira o nosso guia para colaboradores.