使用cefsharp在winform中嵌套浏览器

帅比萌擦擦* 提交于 2019-12-21 20:27:36

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中文帮助文档:

https://github.com/cefsharp/CefSharp/wiki/CefSharp%E4%B8%AD%E6%96%87%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3

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官方示例:

https://github.com/cefsharp/CefSharp.MinimalExample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!