zoukankan      html  css  js  c++  java
  • .net 内嵌 GeckoWebBrowser (firefox) 核心浏览器

    引用nuget包:

    注意:Geckofx45 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;
            }
        }
    }
  • 相关阅读:
    使用 mysql_random_data_load 生成随机数据
    TeamViewer 运行 AlterID 时候报错Cloud not create a fake UUID
    1.6 在WHERE子句中引用取别名的列
    本地登录多实例mysql ,默认登录数据库问题
    统计前10位的占用空间较大的目录
    Oracle查看用户权限
    [LeetCode]Binary Tree Preorder Traversal
    [LeetCode]Insertion Sort List
    [LeetCode]Implement strStr()
    [LeetCode]Remove Element
  • 原文地址:https://www.cnblogs.com/IWings/p/7527304.html
Copyright © 2011-2022 走看看