tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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.WebPage
{
    /// <summary>
    /// 客户端加载网页设置
    /// </summary>
    public class WebBrowserManager
    {
        /// <summary>
        /// CefSharp初始化设置
        /// </summary>
        public static void Initialize()
        {
            var direct = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CefSharp");
            CefSharp.CefSettings settings = new CefSharp.CefSettings();
            settings.LocalesDirPath = Path.Combine(direct, @"locales");
            settings.Locale = "zh-CN";
            settings.BrowserSubprocessPath = Path.Combine(direct, @"CefSharp.BrowserSubprocess.exe");
            CefSharp.Cef.Initialize(settings);
 
            //设置允许客户端与js进行交互(默认为false)
            CefSharp.CefSharpSettings.LegacyJavascriptBindingEnabled=true;
 
            //当程序退出时,关闭并释放CefSharp占用的资源
            CefSharp.CefSharpSettings.ShutdownOnExit=true;
 
            //父线程退出后,子线程也退出
            CefSharp.CefSharpSettings.SubprocessExitIfParentProcessClosed=true;
        }
 
        /// <summary>
        /// 支持高DPI设备显示
        /// </summary>
        public static void EnableHighDPISupport()
        {
            //支持高DPI设备显示
            CefSharp.Cef.EnableHighDPISupport();
        }
 
    }
}