c# C#设置WebBrowser使用Edge内核

开始尝试是用 Microsoft.Toolkit.Forms.UI.Controls.WebView,后来发现一大堆问题,还要求WIN10 SDK的版本之类的。

网上看到的简单的解决办法(只需要修改注册表)(前提是win10系统需要安装Edge浏览器):

这个函数是网上复制的, 传入11000是IE11, 9000是IE9, 只不过当试着传入6000时, 理应是IE6, 可实际却是Edge, 这时进一步测试, 当传入除IE现有版本以外的一些数值时WebBrowser都使用Edge内核

结论

将IE版本号设置为非IE版本的数值就能使用Edge内核
这个方法目前不知道原理, 并且也没有测试过稳定性, 以上内容仅供参考

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestEdgeWebBrowser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            SetFeatures(6000);
            InitializeComponent();
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            web.Navigate("https://liulanmi.com/labs/core.html");
        }

        /// <summary>
        /// 修改注册表信息使WebBrowser使用指定版本IE内核
        /// </summary>
        public static void SetFeatures(UInt32 ieMode)
        {
            if (LicenseManager.UsageMode != LicenseUsageMode.Runtime)
            {
                throw new ApplicationException();
            }
            //获取程序及名称
            string appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            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);
        }
    }
}

  

参考:https://blog.csdn.net/xy1157/article/details/103203545

fffffffffffffffff
test red font.
原文地址:https://www.cnblogs.com/wgscd/p/14393386.html