c# winform中嵌入web

2021-03-16  本文已影响0人  dc的梦呓

在winform中嵌入web,可以用CefSharp。载入web几乎和chrome一样。
在运行入口Main中需加进行一些初始化:

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var cefSetting = new CefSettings() { LogSeverity = LogSeverity.Disable };
            cefSetting.CefCommandLineArgs["enable-system-flash"] = "1";
            cefSetting.CefCommandLineArgs.Add("enable-npapi", "1");
            //关闭同源策略,允许跨域
            cefSetting.CefCommandLineArgs.Add("--disable-web-security", "1");
            Cef.Initialize(cefSetting, shutdownOnProcessExit: true, performDependencyCheck: false);

            Application.ThreadException += Application_ThreadException;
            Application.Run(new MainView());

            Cef.Shutdown();
        }

更多详细用法参看官网

问题

遇到个问题,在开发的电脑上是正常的,但是在用户的电脑上,程序却打不开,也没报错提示。后查看win日志,有System.IO.FileNotFoundException的错误。经查,cefSharp需要VC++ distribution支持:
CefSharp >= v65: VC++ 2015 Redist
Older CefSharp versions: VC ++ 2013 Redist

参考资料:
https://stackoverflow.com/questions/42365731/cefsharp-could-not-load-file-or-assembly-cefsharp-core-dll-or-one-of-its-dep

上一篇下一篇

猜你喜欢

热点阅读