当前位置:网站首页>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.效果

边栏推荐
- f.grid_sample
- 软件积累 -- 截图软件ScreenToGif
- Installation, start and stop of redis7 under Linux
- STM32CUBEMX开发GD32F303(11)----ADC在DMA模式下扫描多个通道
- Mathematical Ideas in AI
- Static route analysis (the longest mask matching principle + active and standby routes)
- 8、统一处理异常(控制器通知@ControllerAdvice全局配置类、@ExceptionHandler统一处理异常)
- YOLOV5学习笔记(三)——网络模块详解
- Observer mode (1)
- Unity3D Button 鼠标悬浮进入与鼠标悬浮退出按钮事件
猜你喜欢

经典链表OJ强训题——快慢双指针高效解法
![LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING](/img/56/fcc8ee6f592abf0a374fc950a3362f.png)
LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING

f.grid_sample

Huawei od dice js

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

Introduction to flask series 】 【 flask - using SQLAlchemy

To write good test cases, you must first learn test design

The principle of complete replication of virtual machines (cloud computing)

mysql view

Drools basic introduction, introductory case, basic syntax
随机推荐
Draw Your Cards
【银行系列第一期】中国人民银行
cudaMemcpy study notes
JetPack component Databinding
Mathematics to solve the problem - circular linked list
如何搭建私有yum源
f.grid_sample
10. Redis implements likes (Set) and obtains the total number of likes
String为什么不可变?
Draw Your Cards
BAT can't sell "Medical Cloud": Hospitals flee, mountains stand, and there are rules
Unity界面总体介绍
10、Redis实现点赞(Set)和获取总点赞数
How to build a private yum source
Brute Force/Adjacency Matrix Breadth First Directed Weighted Graph Undirected Weighted Graph
YOLOV5 study notes (3) - detailed explanation of network module
Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
6、显示评论和回复
mycat的主从关系 垂直分库 水平分表 以及mycat分片联表查询的配置详解(mysql5.7系列)
Face detection based on opencv