一.使用NuGet搜索CefSharp然后下载CefSharp.WinForms和CefSharp.Common
二.引用CefSharp.Windows,CefSharp,CefSharp三个dll
三.将平台换为X86或者X64,Any Cpu无法编译成功
四.使用
(1)配置初始化(一个进程只能配置一次)
1
2
3
4
|
var settings = new CefSettings(); settings.Locale = "zh-CN" ; settings.CefCommandLineArgs.Add( "disable-gpu" , "1" ); //去掉gpu,否则chrome显示有问题 Cef.Initialize(settings); |
(2)初次使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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
出处:https://www.cnblogs.com/yaosj/p/10571829.html
================================================================