在C#的WinForm项目,引入了CefSharp,直接运行程序,会报错.
error : CefSharp.Common contains unmanaged resoures, set your project and solution platform to x86 or x64. Alternatively for AnyCPU Support see github.com/cefsharp/Ce…
需要指定运行的平台,在解决方案右键,选择配置管理器
在活动解决方案平台选择新建,新建一个x86的平台
再次点击启动就没有报错了
在程序源代码Form1.cs引用
using CefSharp;
using CefSharp.WinForms;
改写程序源代码Form1.cs,如下:
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 CefTest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Cef.Initialize(new CefSettings());
ChromiumWebBrowser webBro = new ChromiumWebBrowser("https://www.baidu.com") ; this.Controls.Add(webBro);
webBro.Dock = DockStyle.Fill;
}
}
}
使用CefSharp的浏览器访问百度
运行程序,网页显示在窗体中铺满