using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CefSharp; using CefSharp.WinForms; using System.IO; namespace TProduct.WinFrmUI { /// /// 客户端加载网页设置 /// public class WebBrowserManager { /// /// 是否初始化 /// private static bool IsInitialized = false; private static string CefSharpFolder = "CefSharp"; /// /// CefSharp初始化设置 /// internal static void Initialize() { if (IsInitialized) return; CefSettings settings = new CefSettings(); settings.LocalesDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CefSharpFolder, @"locales"); settings.Locale = "zh-CN"; settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CefSharpFolder, @"CefSharp.BrowserSubprocess.exe"); settings.CefCommandLineArgs.Add("--js-flags", $"--max_old_space_size=2048"); CefSharp.Cef.Initialize(settings); //设置允许客户端与js进行交互(默认为false) CefSharpSettings.WcfEnabled = true; //设置允许客户端与js进行交互(默认为false) //CefSharp.CefSharpSettings.LegacyJavascriptBindingEnabled = true; //当程序退出时,关闭并释放CefSharp占用的资源 CefSharp.CefSharpSettings.ShutdownOnExit = true; //父线程退出后,子线程也退出 CefSharp.CefSharpSettings.SubprocessExitIfParentProcessClosed = true; IsInitialized = true; } /// /// 支持高DPI设备显示 /// public static void EnableHighDPISupport() { //支持高DPI设备显示 CefSharp.Cef.EnableHighDPISupport(); } } }