WinForm WebBrowser 设置IE版本

public enum IeVersion 
{
    IE7 = 7,
    IE8 = 8,
    IE9 = 9,
    IE10 = 10,
    IE11 = 11
}; 

/// <summary>  
/// 修改注册表信息来兼容当前程序
/// </summary>  
public static void SetWebBrowserFeatures(IeVersion ieVersion)
{
    if (LicenseManager.UsageMode != LicenseUsageMode.Runtime) return;
    //获取程序及名称  
    string AppName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

    //得到浏览器的模式的值  
    UInt32 ieMode = GeoEmulationModee((int)ieVersion);

    string featureControlRegKey = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\";
    //设置浏览器对应用程序(appName)以什么模式(ieMode)运行  

    Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION", AppName, ieMode, RegistryValueKind.DWord);
 
    Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", AppName, 1, RegistryValueKind.DWord);
    Registry.SetValue(featureControlRegKey + "FEATURE_AJAX_CONNECTIONEVENTS", AppName, 1, RegistryValueKind.DWord);
    Registry.SetValue(featureControlRegKey + "FEATURE_GPU_RENDERING", AppName, 1, RegistryValueKind.DWord);
    Registry.SetValue(featureControlRegKey + "FEATURE_WEBOC_DOCUMENT_ZOOM", AppName, 1, RegistryValueKind.DWord);
    Registry.SetValue(featureControlRegKey + "FEATURE_NINPUT_LEGACYMODE", AppName, 0, RegistryValueKind.DWord);
}

/// <summary>  
/// 通过版本得到浏览器模式的值  
/// </summary>  
/// <param name="browserVersion"></param>  
/// <returns></returns>  
private static UInt32 GeoEmulationModee(int browserVersion)
{
    UInt32 mode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode.   
    switch (browserVersion)
    {
        case 7:
            mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.   
            break;
        case 8:
            mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.   
            break;
        case 9:
            mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.                      
            break;
        case 10:
            mode = 10000; // Internet Explorer 10.  
            break;
        case 11:
            mode = 11000; // Internet Explorer 11  
            break;
    }
    return mode;
}

WinForm WebBrowser 设置IE版本

上一篇:WPF 释放嵌入资源


下一篇:C# monitor keyboard and print pressed key