当前位置:网站首页>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.效果
边栏推荐
- Static routing + PAT + static NAT (explanation + experiment)
- 221. Largest Square
- 编译Hudi
- LeetCode 每日一题 2022/7/25-2022/7/31
- Hanyuan Hi-Tech 8-channel HDMI integrated multi-service high-definition video optical transceiver 8-channel HDMI video + 8-channel two-way audio + 8-channel 485 data + 8-channel E1 + 32-channel teleph
- Uninstallation of mysql5.7.37 under CentOS7 [perfect solution]
- TCP/IP四层模型
- 19.支持向量机-优化目标和大间距直观理解
- BAT can't sell "Medical Cloud": Hospitals flee, mountains stand, and there are rules
- 【shell基础】判断目录是否为空
猜你喜欢
Coldfusion file read holes (CVE - 2010-2861)
What level of software testing does it take to get a 9K job?
你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?
Mathematics to solve the problem - circular linked list
mmdetection trains a model related command
公司官网建站笔记(六):域名进行公安备案并将备案号显示在网页底部
11、Redis实现关注、取消关注以及关注和粉丝列表
Live Preview | KDD2022 Doctoral Dissertation Award Champion and Runner-up Dialogue
Intranet Infiltration - Privilege Escalation
Drools Rule Properties, Advanced Syntax
随机推荐
The difference between link and @import
Introduction and use of Drools WorkBench
Clustering index, and what is the difference between a clustering index
16. Registration Center-consul
SQL注入 Less47(报错注入) 和Less49(时间盲注)
【shell基础】判断目录是否为空
多线程下类对象的服务承诺探讨
JetPack component Databinding
加密公司向盗窃的黑客提供报价:保留一点,把剩下的归还
11. Redis implements follow, unfollow, and follow and follower lists
Word/Excel fixed table size, when filling in the content, the table does not change with the cell content
BAT can't sell "Medical Cloud": Hospitals flee, mountains stand, and there are rules
LeetCode 1161 最大层内元素和[BFS 二叉树] HERODING的LeetCode之路
try-catch中含return
Software accumulation -- Screenshot software ScreenToGif
Static routing + PAT + static NAT (explanation + experiment)
关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
10. Redis implements likes (Set) and obtains the total number of likes
Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击
First acquaintance with C language -- array