当前位置:网站首页>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.效果
边栏推荐
猜你喜欢
共模电感的仿真应用来了,满满的干货送给大家
Detailed explanation of STP election (step + case)
Drools Rule Properties, Advanced Syntax
Face detection based on opencv
Why is String immutable?
Discourse Custom Header Links
局域网电脑硬件信息收集工具
10. Redis implements likes (Set) and obtains the total number of likes
The final exam first year course
软件积累 -- 截图软件ScreenToGif
随机推荐
The difference between link and @import
1. Non-type template parameters 2. Specialization of templates 3. Explanation of inheritance
StringJoiner in detail
Calculate S=a+aa+…+aa…a
CentOS7下mysql5.7.37的安装【完美方案】
Refuse to work overtime, a productivity tool set developed by programmers
mmdetection训练一个模型相关命令
[1153] The boundary range of between in mysql
19. Support Vector Machines - Intuitive Understanding of Optimization Objectives and Large Spacing
Drools Rule Properties, Advanced Syntax
The effective square of the test (one question of the day 7/29)
Layer 2 broadcast storm (cause + judgment + solution)
Maximum area of solar panel od js
LeetCode Daily Question 2022/7/25-2022/7/31
[1154] How to convert string to datetime
Draw Your Cards
10 权限介绍
直播预告 | KDD2022博士论文奖冠亚军对话
golang GUI for nuxui — HelloWorld
【C语言基础】解决C语言error: expected ‘;‘, ‘,‘ or ‘)‘ before ‘&‘ token