分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

.net 内嵌 GeckoWebBrowser (firefox) 核心浏览器

发布时间:2023-09-06 01:11责任编辑:彭小芳关键词:Web浏览器

引用nuget包:

简单示例:

using Gecko;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 WindowsFormsApp2{ ???public partial class Form1 : Form ???{ ???????GeckoWebBrowser gecko; ???????public Form1() ???????{ ???????????InitializeComponent(); ???????????Xpcom.Initialize("Firefox"); ???????????gecko = new GeckoWebBrowser(); ???????????gecko.CreateControl(); ???????????gecko.NoDefaultContextMenu = true; //禁用右键菜单 ???????????gecko.Dock = DockStyle.Fill; ???????????panel1.Controls.Add(gecko); ???????????gecko.ProgressChanged += Gecko_ProgressChanged; ???????????gecko.CreateWindow += Gecko_CreateWindow; ???????????gecko.DocumentCompleted += Gecko_DocumentCompleted; ???????????gecko.Navigate("http://www.baidu.com"); ???????} ???????private void Gecko_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e) ???????{ ???????????//var executor = new Gecko.JQuery.JQueryExecutor(gecko.Window); ?//先获取到jquery对象 ???????????//executor.ExecuteJQuery("$(‘#a‘)"); ???//然后执行jquery的代码 ???????????using (AutoJSContext context = new AutoJSContext(gecko.Window)) ???????????{ ???????????????string result; ???????????????context.EvaluateScript("3 + 2;", out result); ???????????????context.EvaluateScript("‘hello‘ + ‘ ‘ + ‘world‘;", out result); ???????????} ???????????progressBar1.Value = 0; ???????} ???????private void Gecko_CreateWindow(object sender, GeckoCreateWindowEventArgs e) ???????{ ???????????e.InitialHeight = 500; ???????????e.InitialWidth = 500; ???????} ???????private void Gecko_ProgressChanged(object sender, GeckoProgressEventArgs e) ???????{ ???????????if (e.MaximumProgress == 0 ) ???????????????return; ???????????var value = (int)Math.Min(100, (e.CurrentProgress * 100) / e.MaximumProgress); ???????????if (value == 100) ???????????????return; ???????????progressBar1.Value = value; ???????} ???}}

.net 内嵌 GeckoWebBrowser (firefox) 核心浏览器

原文地址:http://www.cnblogs.com/IWings/p/7527304.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved