1. 创建winform程序
2. 在项目中,右击引用,选择nuget包,引入cefsharp.winforms包
3. 更改winform生成配置,之前的cefsharp.winforms不支持anyCPU配置,现在支持了
右击项目,选择属性,选择生成,更改生成配置勾上“32位优先”
4. 更改项目的csproj文件,添加
<CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
5. 更改项目中的App.config文件,添加:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="x86"/>
</assemblyBinding>
</runtime>
6. 使用cefsharp:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
namespace embebbedChromium
{
public partial class Form1 : Form
{
public ChromiumWebBrowser chromeBrowser;
public Form1()
{
InitializeComponent();
// Start the browser after initialize global component
InitializeChromium();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
// Initialize cef with the provided settings
Cef.Initialize(settings);
// Create a browser component
chromeBrowser = new ChromiumWebBrowser("https://blog.csdn.net/xingkongtianyuzhao");
// Add it to the form and fill it to the form window.
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
}
}
后面的可以参考这篇入门教程:https://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application
其他参考资料:
CefSharp中文帮助文档:
C#读取本地文件:
https://www.cnblogs.com/yaotome/p/9002172.html
C#使用cefsharp:
https://www.cnblogs.com/lonelyxmas/p/10249454.html
CefSharp调用摄像头:
https://www.cnblogs.com/lonelyxmas/p/9402034.html
CefSharp官方示例:
来源:CSDN
作者:星空你好
链接:https://blog.csdn.net/xingkongtianyuzhao/article/details/103646371