WebBrowser WebBrowser WebBrowser Constructor

Définition

Initialise une nouvelle instance de la classe WebBrowser.Initializes a new instance of the WebBrowser class.

public:
 WebBrowser();
public WebBrowser ();
Public Sub New ()

Exceptions

Le contrôle WebBrowser est hébergé à l'intérieur d'Internet Explorer.The WebBrowser control is hosted inside Internet Explorer.

Exemples

L’exemple de code suivant illustre l’utilisation de ce membre.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

Remarques

Par défaut, le WebBrowser contrôle est vide.By default, the WebBrowser control is empty. Pour accéder à un document initial, définissez la Url propriété.To navigate it to an initial document, set the Url property.

Sécurité

SecurityPermission
pour que les appelants immédiats utilisent ce contrôle.for immediate callers to use this control. Valeur de la LinkDemanddemande:; Jeux d’autorisations nommés: FullTrust.Demand value: LinkDemand; Named Permission Sets: FullTrust.

S’applique à