当前位置:网站首页>CefSharp入门-winform
CefSharp入门-winform
2022-07-31 02:43:00 【故里2130】
CefSharp支持HTML,CSS,JavaScript,可以在CS中像web网站那样操作。与winform中自带的webBrowser一样,只是CefSharp是独立的,基于Chrome浏览器,而webBrowser基于IE浏览器。现在简单的体验一下效果。
1.首先建立一个winform程序
项目选择.NET Framework4.8框架
在nuget中,下载cefsharp,选择版本是83.4.20。这里使用高版本的话,会出现黑屏的问题。只有此版本目前不会,而且小于此版本的也不会出现黑屏(经过大量的测试而知)

2.然后运行的话会报错,增加以下几个地方
在项目文件中增加如下代码

<CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>在配置文件中增加
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="x86"/>
</assemblyBinding>
</runtime>然后重新启动即可。
3. 主界面中,增加以下代码
using CefSharp;
using CefSharp.WinForms;
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;
namespace cef1
{
public partial class Form1 : Form
{
public ChromiumWebBrowser chromeBrowser;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
InitializeChromium();//初始化
}
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
settings.Locale = "zh-CN";
// Initialize cef with the provided settings
Cef.Initialize(settings);
// Create a browser component
chromeBrowser = new ChromiumWebBrowser("https://blog.csdn.net/u012563853");
// 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();
}
}
}
4.效果

边栏推荐
- 基于opencv实现人脸检测
- 真正的CTO,是一个懂产品的技术人
- 16. Registration Center-consul
- Difference between CMOS and TTL?
- 【Bank Series Phase 1】People's Bank of China
- The Sad History of Image Processing Technology
- 【银行系列第一期】中国人民银行
- StringJoiner详解
- Brute Force/Adjacency Matrix Breadth First Directed Weighted Graph Undirected Weighted Graph
- 共模电感的仿真应用来了,满满的干货送给大家
猜你喜欢

经典链表OJ强训题——快慢双指针高效解法

19. Support Vector Machines - Intuitive Understanding of Optimization Objectives and Large Spacing

Unity界面总体介绍

MPPT太阳能充放电控制器数据采集-通过网关采集电池电压容量电量SOC,wifi传输

Detailed explanation of STP election (step + case)

7、私信列表

Teach you how to configure Jenkins automated email notifications

工程(五)——小目标检测tph-yolov5

7. List of private messages

静态路由解析(最长掩码匹配原则+主备路由)
随机推荐
AtCoder Beginner Contest 261 部分题解
16、热帖排行
LeetCode 每日一题 2022/7/25-2022/7/31
Maximum area of solar panel od js
AtCoder Beginner Contest 261 Partial Solution
TCP/IP四层模型
The final exam first year course
分布式与集群是什么 ? 区别是什么?
多线程下类对象的服务承诺探讨
print task sorting js od huawei
CorelDRAW2022精简亚太新增功能详细介绍
8、统一处理异常(控制器通知@ControllerAdvice全局配置类、@ExceptionHandler统一处理异常)
Clustering index, and what is the difference between a clustering index
英特尔软硬优化,赋能东软加速智慧医疗时代到来
try-catch中含return
Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care
Introduction and use of Drools WorkBench
拒绝加班,程序员开发的效率工具集
【shell基础】判断目录是否为空
YOLOV5 study notes (3) - detailed explanation of network module