先说下步骤,然后在讲细节
注意:前四步做成x86,第五步是将x86做成x64
1.下载Cefsahrp、
2.拷贝Main函数文件代码
3.浏览器显示载体控件代码
4.该生成目标为x86
5.x86改成x64在最后附上
下面是细节
1.不说了
2.拷贝Main函数文件代码
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CefSharpDemo
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
InitializeCefSharp();
Application.Run(new Form1());
}
#region CEF
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp()
{
// enable High-DPI support on Windows 7 or newer.
Cef.EnableHighDPISupport();
var settings = new CefSettings();
// Set BrowserSubProcessPath based on app bitness at runtime
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "" : "",
"CefSharp.BrowserSubprocess.exe");
//禁用GPU
settings.CefCommandLineArgs.Add("disable-gpu", "1");
settings.CefCommandLineArgs.Add("no-proxy-server", "1");
settings.CachePath = Directory.GetCurrentDirectory() + @"\Cache";
// Make sure you set performDependencyCheck false
Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
}
// Will attempt to load missing assembly from either x86 or x64 subdir
// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
private static Assembly Resolver(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("CefSharp"))
{
string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
assemblyName);
return File.Exists(archSpecificPath)
? Assembly.LoadFile(archSpecificPath)
: null;
}
return null;
}
#endregion
}
}
3.浏览器显示载体控件代码
public Form1()
{
InitializeComponent();
string url = "chrome://extensions/";
ChromiumWebBrowser webview = new ChromiumWebBrowser(url);
webview.Dock = DockStyle.Fill;
this.panel1.Controls.Add(webview);
}
4.自己操作了
5.打开工程文件:把x86的部分拷贝一份,批量换成x64,再把生成目标换成x64即可