zoukankan      html  css  js  c++  java
  • winfrom中的webbrowser内核版本修改

    vs2008,winfrom中的webbrowser  其内核默认为IE7,当网页中存在IE7不支持的属性时回报错。

              
         private void Form1_Load(object sender, EventArgs e)
            {
    
                SetWebBrowserFeatures(11);          
            }
    
    
     static void SetWebBrowserFeatures(int ieVersion)
            {
                // don't change the registryif running in-proc inside Visual Studio 
                if (LicenseManager.UsageMode != LicenseUsageMode.Runtime) return;
                //获取程序及名称  
                var appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                //得到浏览器的模式的值 
                UInt32 ieMode = GeoEmulationModee(ieVersion);
                var featureControlRegKey = @"HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainFeatureControl";
                //设置浏览器对应用程序(appName)以什么模式(ieMode)运行  
                Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION", appName, ieMode, RegistryValueKind.DWord);
                // enable the features which are "On" for the full Internet Explorer browser  //不晓得设置有什么用  
                Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", appName, 1, RegistryValueKind.DWord);
            }
    
            static int GetBrowserVersion()
            { 
                 int browserVersion = 0; 
                 using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftInternet Explorer", RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.QueryValues)) { var version = ieKey.GetValue("svcVersion"); 
                     if (null == version)
                     { 
                         version = ieKey.GetValue("Version");
                         if (null == version) throw new ApplicationException("Microsoft Internet Explorer is required!"); 
                     } 
                     int.TryParse(version.ToString().Split('.')[0], out browserVersion); } //如果小于7 
                 if (browserVersion < 7) 
                 { throw new ApplicationException("不支持的浏览器版本!"); } return browserVersion; 
             }
    
            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;break; 
                     case 8: mode = 8000;break; 
                     case 9: mode = 9000;break;
                     case 10: mode = 10000;break; 
                     case 11: mode = 11000;break; 
                 } 
                 return mode;
             }
    
  • 相关阅读:
    #2020征文TV#【鸿蒙基地】鸿蒙从窗口开始:Page Ability诞生记
    设计器打开某表单时提示:[某某表单]已经由用户[xxx]打开需解锁
    有效性设置解疑
    表单打开时显示空白页面解决办法
    工作流_知会设置
    单元格中既有公式又可以录入数据,怎么实现?
    更改系统时间
    下拉框改变后,如何清空后面几个单元格的值?
    如何调整人员的部门?
    如何修改iis访问端口
  • 原文地址:https://www.cnblogs.com/lq0418/p/10312693.html
Copyright © 2011-2022 走看看