開始嘗試是用 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
