技术标签: C# Visual Studio C# CefSharp
1.点击“引用”,右键"管理Nuget程序包",搜索框里输入"CefSharp",选择"CefSharp.WinForms",安装。
这样就会自动把CefSharp需要的拓展给安装齐全了,之后在解决方案的 packages 目录里会有4个文件夹 cef.redist.x64.版本号,cef.redist.x86.版本号,CefSharp.Common.版本号,CefSharp.WinForms.版本号。
2.使用代码:
using CefSharp.WinForms;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
using ZKKC.Lib;
namespace Wb
{
public partial class FormMain : Form
{
private CefSharp.WinForms.ChromiumWebBrowser wb_main;
delegate void SetWebBrowserVisible(Boolean result);
public FormMain()
{
InitializeComponent();
}
/// <summary>
/// 初始化WebBrowser
/// </summary>
public void InitWb()
{
String url = "https://ie.icoa.cn/";
this.wb_main = new CefSharp.WinForms.ChromiumWebBrowser(url);
this.wb_main.ActivateBrowserOnCreation = false;
this.wb_main.Dock = System.Windows.Forms.DockStyle.Fill;
this.wb_main.Location = new System.Drawing.Point(0, 0);
this.wb_main.Name = "wb_main";
this.wb_main.Size = new System.Drawing.Size(800, 450);
this.wb_main.TabIndex = 0;
this.wb_main.FrameLoadStart += new System.EventHandler<CefSharp.FrameLoadStartEventArgs>(this.wb_main_FrameLoadStart);
this.wb_main.FrameLoadEnd += new System.EventHandler<CefSharp.FrameLoadEndEventArgs>(this.wb_main_FrameLoadEnd);
this.pl_main.Controls.Add(this.wb_main);
try
{
this.toToggleWbVisible(false); //直接设置Visible=false,会导致浏览器不会访问地址,所以在访问底之前手动设置为不可见
this.wb_main.Load(url);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
private void FormMain_Load(object sender, EventArgs e)
{
//初始化WebBrowser
InitWb();
}
/// <summary>
/// 修改浏览器插件的可见性
/// </summary>
/// <param name="result"></param>
private void toToggleWbVisible(Boolean result)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.wb_main.InvokeRequired)
{
SetWebBrowserVisible d = new SetWebBrowserVisible(toToggleWbVisible);
this.Invoke(d, new object[] { result });
}
else
{
this.wb_main.Visible = result;
}
}
/// <summary>
/// 浏览器开始加载事件把浏览器设置为不可见
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void wb_main_FrameLoadStart(object sender, CefSharp.FrameLoadStartEventArgs e)
{
//刷新 about:blank 页面时不隐藏控件
if (!e.Url.Equals("about:blank"))
{
this.toToggleWbVisible(false);
}
}
/// <summary>
/// 浏览器结束加载事件把浏览器设置为可见
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void wb_main_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
{
this.toToggleWbVisible(true);
}
}
}
visual studio 2019编辑结构体 利用visual studio 2019编辑结构体有警告? 代码示意如下:...
之前我有一篇文章讲的是使用Visual Studio 2017 创建Linux C++ 项目(使用VS2017调试Linux C++代码),使用IDE的好处就是方便编码和调试。工作中也一直以这种方式开发Linux平台的项目,使用了大概两年多,总体上可以满足开发需求,但是还存在一些bug,或者说令人不太满意的地方。 问题1:本地文件和远程同步问题 项目中如果有脚本或者配置等文本文件,由于这些文件不参...
Visual Studio 2019 离线安装教程 Visual Studio 2019 经过精心设计,可在各种网络和计算机配置中良好运行。 虽然我们建议你试用 Visual Studio Web 安装程序—这是一个小巧文件,可及时提供最新修补程序和功能—但我们知道对你而言这也许并不可行。 例如,你的 Internet 连接不可靠或带宽较低。 ...
1.编译 在Visual Studio 2019命令行里面输入,: 1.【到E:\Open_source\tiff-4.1.0\libtiff】:E: 回车, cd E:\Open_source\tiff-4.1.0\libtiff 3.【编译】:nmake /f makefile.vc 编译后会得到两种库:libtiff.lib 和 libtiff_i.lib...
1、下载对应版本LibTorch,只用作预测下载CPU版本即可:官方网站 2、Visual Studio中,配置管理器,将配置改成所有配置,平台改为所有平台。 3、Visual Studio中,项目>属性>C/C++>常规>附加包含目录,添加: 4、Visual Studio中,项目>属性>链接器>常规>链接库依赖目录项,添加: 5、Visual S...
文章目录 小结 问题 找不到boost的源文件 boost库的版本问题 boost 1.7.0库的安装 添加boost 1.7.0库到VS 2019工程 编译问题 参考 小结 在Visual Studio 2019使用了boost 1.7.0库,经过编译boost 1.7.0库,再添加配置到VS 2019工程中,进行了成功地测试。 问题 找不到boost的源文件 如果没有安装boost库,会在Vi...
文章目录 1 编码 (1) code编码 (2) 控制台编码 (3) txt文件编码 (4) 控制台编码 2 中文输出 (1) 更改 `locale` 显示中文 1).`cout` 与 `wcout` 2). `ofstream ` 与 `wofstream` 3). `printf` 和 `wprintf` (2) 通过 `_setmode()`输出中文 3 中文乱码问题 (1) 代码与编程环境...
最近要安装libQtShowsocks但是要求安装botan,就试着编译了一下。这里是官网的安装步骤。 以下是具体的步骤。(要先安装python2.6或以上的版本) 在GitHub下载压缩包。 在本地解压,打开vs的命令行工具(编译64位的botan就打开64位命令行工具) 定位到解压的botan文件,输入以下命令: (如果要编译32位的添加–cpu=x86,默认的是64位) 输入nm...