2017-06-03 290 views
0

使用下面的代碼來捕捉心智圖網址的截圖:web瀏覽器C#對象:設置谷歌瀏覽器爲默認瀏覽器

using (WebBrowser browser = new WebBrowser()) 
      {     
       browser.Width = 900; 
       browser.Height = 900; 
       browser.ScrollBarsEnabled = true; 

       // This will be called when the page finishes loading 
       browser.DocumentCompleted += Program.OnDocumentCompleted; 

       browser.Navigate("https://app.mindmup.com/map/_free/2017/06/4e6750b0484011e7a155fd63d7b56500"); 

       // This prevents the application from exiting until 
       // Application.Exit is called 
       Application.Run(); 
      } 

然而,心智圖網址無法在IE瀏覽器,因此無法捕捉到的截圖打開。任何人都可以請建議如何使用網頁瀏覽器對象時,將谷歌瀏覽器設置爲瀏覽器。或者其他一些代碼捕獲屏幕截圖

回答

0

您無法更改WebBrowser使用哪種瀏覽器。然而,也有一些其他的解決方案:

1.使用其他Web瀏覽器

我會建議CefSharp。它使用鉻,它非常適合您的項目。

更多CefSharp:here

2.強制web瀏覽器運行IE11

默認情況下,Internet Explorer 7中由web瀏覽器使用。幸運的是,你可能會強迫它選擇一個更新的版本。

加載表單之前,先運行createRegistry()。你可以在Program.cs中調用它。如果要恢復註冊表,請運行removeRegistry()。

public static void createRegistry() 
    { 
     string filename = Process.GetCurrentProcess().MainModule.FileName; 
     filename = filename.Substring(filename.LastIndexOf('\\') + 1, filename.Length - filename.LastIndexOf('\\') - 1); 
     if (filename.Contains("vhost")) 
      filename = filename.Substring(0, filename.IndexOf('.') + 1) + "exe"; 

      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true).SetValue(filename, 11001, RegistryValueKind.DWord); 

      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BEHAVIORS", true).SetValue(filename, 11001, RegistryValueKind.DWord); 

      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true).SetValue(filename, 11001, RegistryValueKind.DWord); 

      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BEHAVIORS", true).SetValue(filename, 11001, RegistryValueKind.DWord); 
    } 

    public static void removeRegistry() 
    { 
     string filename = Process.GetCurrentProcess().MainModule.FileName; 
     filename = filename.Substring(filename.LastIndexOf('\\') + 1, filename.Length - filename.LastIndexOf('\\') - 1); 
     if (filename.Contains("vhost")) 
      filename = filename.Substring(0, filename.IndexOf('.') + 1) + "exe"; 
     try 
     { 
      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true).DeleteValue(filename); 
     } 
     catch 
     { 

     } 
     try 
     { 
      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BEHAVIORS", true).DeleteValue(filename); 
     } 
     catch 
     { 

     } 
     try 
     { 
      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true).DeleteValue(filename); 
     } 
     catch 
     { 

     } 
     try 
     { 
      Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BEHAVIORS", true).DeleteValue(filename); 
     } 
     catch 
     { 

     } 
    } 
+0

思維導圖根本無法用於ie11。將嘗試使用cef# – nina

+0

使用cefsharp並不像web瀏覽器那麼容易。由於版權問題,Cef的唯一缺點是無法播放MP3,MP4。無論如何,祝你好運! –

+0

我的要求只是從特定的網址截圖。是否有其他出路,以便我只能使用c#代碼,而不必使用cef# – nina