zoukankan      html  css  js  c++  java
  • .net 设置Webbowser 版本

    .net 里的Webbowser控件默认情况是用IE7来渲染

    可修改注册表试用是最新的版本来渲染:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Security;
    using Microsoft.Win32;
    using System.IO;
    
    namespace wgscd
    {
    
    
        public enum BrowserEmulationVersion
            {
                Default = 0,
                Version7 = 7000,
                Version8 = 8000,
                Version8Standards = 8888,
                Version9 = 9000,
                Version9Standards = 9999,
                Version10 = 10000,
                Version10Standards = 10001,
                Version11 = 11000,
                Version11Edge = 11001
            }
        public static class WBEmulator
            {
                private const string InternetExplorerRootKey = @"SoftwareMicrosoftInternet Explorer";
    
                public static int GetInternetExplorerMajorVersion()
                {
                    int result;
    
                    result = 0;
    
                    try
                    {
                        RegistryKey key;
    
                        key = Registry.LocalMachine.OpenSubKey(InternetExplorerRootKey);
    
                        if (key != null)
                        {
                            object value;
    
                            value = key.GetValue("svcVersion", null) ?? key.GetValue("Version", null);
    
                            if (value != null)
                            {
                                string version;
                                int separator;
    
                                version = value.ToString();
                                separator = version.IndexOf('.');
                                if (separator != -1)
                                {
                                    int.TryParse(version.Substring(0, separator), out result);
                                }
                            }
                        }
                    }
                    catch (SecurityException)
                    {
                        // The user does not have the permissions required to read from the registry key.
                    }
                    catch (UnauthorizedAccessException)
                    {
                        // The user does not have the necessary registry rights.
                    }
    
                    return result;
                }
                private const string BrowserEmulationKey = InternetExplorerRootKey + @"MainFeatureControlFEATURE_BROWSER_EMULATION";
    
                public static BrowserEmulationVersion GetBrowserEmulationVersion()
                {
                    BrowserEmulationVersion result;
    
                    result = BrowserEmulationVersion.Default;
    
                    try
                    {
                        RegistryKey key;
    
                        key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true);
                        if (key != null)
                        {
                            string programName;
                            object value;
    
                            programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
                            value = key.GetValue(programName, null);
    
                            if (value != null)
                            {
                                result = (BrowserEmulationVersion)Convert.ToInt32(value);
                            }
                        }
                    }
                    catch (SecurityException)
                    {
                        // The user does not have the permissions required to read from the registry key.
                    }
                    catch (UnauthorizedAccessException)
                    {
                        // The user does not have the necessary registry rights.
                    }
    
                    return result;
                }
                public static bool SetBrowserEmulationVersion(BrowserEmulationVersion browserEmulationVersion)
                {
                    bool result;
    
                    result = false;
    
                    try
                    {
                        RegistryKey key;
    
                        key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true);
    
                        if (key != null)
                        {
                            string programName;
    
                            programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
    
                            if (browserEmulationVersion != BrowserEmulationVersion.Default)
                            {
                                // if it's a valid value, update or create the value
                                key.SetValue(programName, (int)browserEmulationVersion, RegistryValueKind.DWord);
                            }
                            else
                            {
                                // otherwise, remove the existing value
                                key.DeleteValue(programName, false);
                            }
    
                            result = true;
                        }
                    }
                    catch (SecurityException)
                    {
                        // The user does not have the permissions required to read from the registry key.
                    }
                    catch (UnauthorizedAccessException)
                    {
                        // The user does not have the necessary registry rights.
                    }
    
                    return result;
                }
    
                public static bool SetBrowserEmulationVersion()
                {
                    int ieVersion;
                    BrowserEmulationVersion emulationCode;
    
                    ieVersion = GetInternetExplorerMajorVersion();
    
                    if (ieVersion >= 11)
                    {
                        emulationCode = BrowserEmulationVersion.Version11;
                    }
                    else
                    {
                        switch (ieVersion)
                        {
                            case 10:
                                emulationCode = BrowserEmulationVersion.Version10;
                                break;
                            case 9:
                                emulationCode = BrowserEmulationVersion.Version9;
                                break;
                            case 8:
                                emulationCode = BrowserEmulationVersion.Version8;
                                break;
                            default:
                                emulationCode = BrowserEmulationVersion.Version7;
                                break;
                        }
                    }
    
                    return SetBrowserEmulationVersion(emulationCode);
                }
                public static bool IsBrowserEmulationSet()
                {
                    return GetBrowserEmulationVersion() != BrowserEmulationVersion.Default;
                }
    
    
    
    
            }
    
        /*
         调用 :
         *  if (!WBEmulator.IsBrowserEmulationSet())
                {
                    WBEmulator.SetBrowserEmulationVersion();
             }
         */
    
    
    
    
    
    
    }
    

      

    或者使用第三方的浏览器控件:

    项目基于WebKit.NET 0.5开发
    google code地址:https://code.google.com/archive/p/open-webkit-sharp/
    github网址 : https://github.com/Erls-Corporation/open-webkit-sharp

     use the WebKit.NET :https://sourceforge.net/projects/webkitdotnet/

  • 相关阅读:
    7月15日考试 题解(链表+状压DP+思维题)
    暑假集训日记
    C# .NET 使用 NPOI 生成 .xlsx 格式 Excel
    JavaSE 基础 第42节 局部内部类
    JavaSE 基础 第41节 匿名内部类
    JavaSE 基础 第40节 内部类概述
    JavaSE 基础 第39节 接口的应用
    JavaSE 基础 第38节 接口的实现
    JavaSE 基础 第37节 接口概述
    JavaSE 基础 第36节 抽象类概述与使用
  • 原文地址:https://www.cnblogs.com/wgscd/p/9323673.html
Copyright © 2011-2022 走看看