简介:
CefSharp让您在.NET应用程序中嵌入Web程序。它是基于Google引擎而的开源框架。
运行环境: .net framework **环境和 vc++ 2013 runtime (x86/x64)**
配置CefSharp
通过 NuGet 包来使用:
例如:
安装版本为 39.0.1 的 CefSharp.WinForms 程序包
Install-Package CefSharp.WinForms -Version 39.0.1
手动配置:
引用:
CefSharp.dll
CefSharp.Core.dll
CefSharp.WinForms.dll
拷贝以下dll到debug目录下:
![这里写图片描述](http://img.blog.csdn.net/20161220132452131?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDA4NTQyMw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
编写第一段CefSharp代码
//设置语言环境 以上这段代码一定要在new ChromiumWebBrowser之前调用
var setting = new CefSharp.CefSettings()
setting.Locale = "zh-CN"
//缓存路径
setting.CachePath = "/BrowserCache"
//浏览器引擎的语言
setting.AcceptLanguageList = "zh-CN,zh;q=0.8"
setting.LocalesDirPath = "/localeDir"
//日志文件
setting.LogFile = "/LogData"
setting.PersistSessionCookies = true
setting.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
setting.UserDataPath = "/userData"
CefSharp.Cef.Initialize(setting, true, false)
CefSharp常用按钮
手动引用:
using cef
using CefSharp
//调试
webView.GetBrowser().ShowDevTools()
//刷新
webView.GetBrowser().Reload()
//上一页
webView.GetBrowser().GoBack()
//下一页
webView.GetBrowser().GoForward()
资源清理
static ChromiumWebBrowser()
{
if (CefSharpSettings.ShutdownOnExit)
{
Application.ApplicationExit += OnApplicationExit;
}
}
private static void OnApplicationExit(object sender, EventArgs e)
{
Cef.Shutdown();
}
try
{
browser.CloseDevTools();
browser.GetBrowser().CloseBrowser(true);
}
catch { }
try
{
if (browser != null)
{
browser.Dispose();
Cef.Shutdown();
}
}
catch { }