1. 程式人生 > >.Net 改變WebBrowser 核心版本

.Net 改變WebBrowser 核心版本

要用到WebBrowser時發現預設的是IE7版本,太低,有些網頁顯示不正常,將下面的方法在WebBrowser載入網頁前執行,即可,會將版本改為 IE9

private static void WebBrowserVersionEmulation()
{
    const string BROWSER_EMULATION_KEY = 
    @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
    //
    // app.exe and app.vshost.exe
    String appname = Process.GetCurrentProcess().ProcessName + ".exe"
; // // Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive. const int browserEmulationMode = 9999; RegistryKey browserEmulationKey = Registry.CurrentUser.OpenSubKey(BROWSER_EMULATION_KEY,RegistryKeyPermissionCheck.ReadWriteSubTree) ?? Registry.CurrentUser.CreateSubKey(BROWSER_EMULATION_KEY); if
(browserEmulationKey != null) { browserEmulationKey.SetValue(appname, browserEmulationMode, RegistryValueKind.DWord); browserEmulationKey.Close(); } }