背景
项目当中需要在Winform窗体中嵌入网页,虽然微软自带了WebBrowser控件,但是她是以IE模式运行的,兼容性实在太差,找了一圈发现有个叫CefSharp的家伙还不错,于是就拿来玩了一下。
CefSharp 主要特征
- 支持.NET Framework 4.5.2+
- 支持Winform,WPF
- 基于Chromium内核
- 支持Javascript互操作
- BSD商业开源,地址https://github.com/cefsharp/CefSharp
快速入门
注:笔者的环境是Visual Studio 2019.
- 新建winform项目。
- 打开Nuget包管理器。
- 搜索CefSharp.WinForms,可以看到目前最新的版本是81.x, 点击安装。
- 编译项目,会出现以下错误:
CefSharp.Common is unable to proceeed as your current Platform is ‘AnyCPU’. To target AnyCPU please read https://github.com/cefsharp/CefSharp/issues/1714. Alternatively change your Platform to x86 or x64 and the relevant files will be copied automatically. For details on changing your projects Platform see https