2009-03-01 7 views

Répondre

7

Vous pouvez gérer l'événement de navigation, définir la propriété Cancel de WebBrowserNavigatingEventArgs sur true et utiliser Process.Start pour ouvrir l'URL dans Internet Explorer.

Quelque chose comme ceci:

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) 
{ 
    // prevents WebBrowser to navigate 
    if (e.Url.Host.Length > 0) // Otherwise the default about:blank when you init the control doesn't work 
    { 
     e.Cancel = true; 

     // Open the URL in an IE window 
     System.Diagnostics.Process process = new System.Diagnostics.Process(); 
     process.StartInfo.FileName = e.Url.ToString(); 
     process.Start(); 
    } 
} 
+2

fonctionne comme un charme - presque. J'ai dû vérifier si le e.URL.Host.Length> 0 avant d'annuler la navigation. Lorsque je configure le contrôle webbrowser, il navigue vers "about: blank" et lorsque j'annule celui-ci, je ne peux définir aucun texte de document. De toute façon, je l'ai eu, grâce à votre aide ... à la vôtre –

Questions connexes