一.使用NuGet搜索CefSharp然后下载CefSharp.WinForms和CefSharp.Common
二.引用CefSharp.Windows,CefSharp,CefSharp三个dll
三.将平台换为X86或者X64,Any Cpu无法编译成功
四.使用
(1)配置初始化(一个进程只能配置一次)
var settings = new CefSettings(); settings.Locale = "zh-CN"; settings.CefCommandLineArgs.Add("disable-gpu", "1");//去掉gpu,否则chrome显示有问题 Cef.Initialize(settings);
(2)初次使用
private ChromiumWebBrowser browser = null; private void FrushBrowser(string url) { if (browser == null) { browser = new ChromiumWebBrowser("") { Dock = DockStyle.Fill, }; } if (!string.IsNullOrEmpty(url)) browser.Load(url); else browser.LoadHtml(""); }
(3)释放
browser.Dispose();
browser=null;
CefSharp.Cef.Shutdown();
(4)其他配置
去掉代理,增加加载网页速度
settings.CefCommandLineArgs.Add("proxy-auto-detect", "0");
settings.CefCommandLineArgs.Add("no-proxy-serve", "1");
参考:
wiki地址:https://github.com/cefsharp/CefSharp/wiki/CefSharp中文帮助文档
demo地址:https://github.com/cefsharp/CefSharp.MinimalExample