在.NET中使用GeckoFX 29

简介:

GeckoFX is a .NET control, that works similarly to “System.Windows.Forms.WebBrowser” Control, while being cross platform, and offering much more control, it is in my opinion, a great replacement for the “System.Windows.Forms.WebBrowser”.

GeckoFX is based on the same engine as Firefox, the Mozilla Gecko.

This is an example on how to use it in Visual Studio.

This is a great replacement for Forms.WebBrowser control.

To get this working, you need to first download the GeckoFX from here:

https://bitbucket.org/geckofx/

During the writing of this, the last available version was the “GeckoFX-29.0”, so I downloaded that from here, if while you download this found a newer version, which is very likely, be careful to what XUL version you download on the next step:

https://bitbucket.org/geckofx/geckofx-29.0/downloads

and last revision:

https://bitbucket.org/geckofx/geckofx-29.0/downloads/GeckoFx-Windows-29.0-0.11.zip

After that, you need to download the XULRunner runtime from Mozilla website, it is very important that you download a version from here that matches the same version as the GeckoFX version.

Here is a version list that will help you know what XULRunner version you need:

https://bitbucket.org/geckofx/geckofx/wiki/Version_lists

And download from:
http://ftp.mozilla.org/pub/mozilla.org/xulrunner/

In my case, I downloaded version “29.0” from:
http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/29.0/runtimes/xulrunner-29.0.en-US.win32.zip

Extract the contents of the archive in the same folder as the executable, the same folder that has the WindowsFormsApplication1.exe, if you choose to extract to a different folder, be sure to modify the code to point to the new folder.

After that, start Visual studio, create a new C# Windows form project, and add refrences to both “Geckofx-Winforms.dll”, and “Geckofx-Core.dll” in the project refrences.

You may also need to add those line to the top of the file:

using Gecko;
using System.IO;
using System.Linq;
using System.Reflection;

And in the form constructor, you need to add some code to initiate the GeckoFX control, this code will be added after the “InitializeComponent()” function call, like this:

    GeckoWebBrowser browser;
    public Form1()
    {
        InitializeComponent();
 
        var app_dir = Path.GetDirectoryName(Application.ExecutablePath);
        Gecko.Xpcom.Initialize(Path.Combine(app_dir, "xulrunner"));
 
        browser = new GeckoWebBrowser();
 
        browser.Dock = DockStyle.Fill;
        this.browser.Name = "browser";
 
        this.Controls.Add(browser);
    }

And add this one line to the form load event handler:

    private void Form1_Load(object sender, EventArgs e)
    {
        browser.Navigate("http://www.wikipedia.org");
    }

Important Problem: you need to go to your project properties, and in the ‘build’ tab, change the platform target to x86 for (all configurations), instead of “Any CPU”.

Before running the application for the first time, do not forget that you need to extract the xulrunner in the “\bin\Debug” or “\bin\Release” folder.

This is the result:

GeckoFX-01




本文转自黄聪博客园博客,原文链接:http://www.cnblogs.com/huangcong/p/8177740.html,如需转载请自行联系原作者
相关文章
|
3月前
|
开发框架 前端开发 JavaScript
ASP.NET MVC 教程
ASP.NET 是一个使用 HTML、CSS、JavaScript 和服务器脚本创建网页和网站的开发框架。
48 7
|
3月前
|
存储 开发框架 前端开发
ASP.NET MVC 迅速集成 SignalR
ASP.NET MVC 迅速集成 SignalR
75 0
|
4月前
|
开发框架 前端开发 .NET
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
56 0
|
4月前
|
开发框架 前端开发 安全
ASP.NET MVC 如何使用 Form Authentication?
ASP.NET MVC 如何使用 Form Authentication?
|
4月前
|
开发框架 .NET
Asp.Net Core 使用X.PagedList.Mvc.Core分页 & 搜索
Asp.Net Core 使用X.PagedList.Mvc.Core分页 & 搜索
145 0
|
7月前
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
212 0
|
7月前
|
开发框架 前端开发 JavaScript
JavaScript云LIS系统源码ASP.NET CORE 3.1 MVC + SQLserver + Redis医院实验室信息系统源码 医院云LIS系统源码
实验室信息系统(Laboratory Information System,缩写LIS)是一类用来处理实验室过程信息的软件,云LIS系统围绕临床,云LIS系统将与云HIS系统建立起高度的业务整合,以体现“以病人为中心”的设计理念,优化就诊流程,方便患者就医。
86 0
|
7月前
|
开发框架 前端开发 .NET
C# .NET面试系列六:ASP.NET MVC
<h2>ASP.NET MVC #### 1. MVC 中的 TempData\ViewBag\ViewData 区别? 在ASP.NET MVC中,TempData、ViewBag 和 ViewData 都是用于在控制器和视图之间传递数据的机制,但它们有一些区别。 <b>TempData:</b> 1、生命周期 ```c# TempData 的生命周期是短暂的,数据只在当前请求和下一次请求之间有效。一旦数据被读取,它就会被标记为已读,下一次请求时就会被清除。 ``` 2、用途 ```c# 主要用于在两个动作之间传递数据,例如在一个动作中设置 TempData,然后在重定向到另
364 5
|
存储 开发框架 前端开发
[回馈]ASP.NET Core MVC开发实战之商城系统(五)
经过一段时间的准备,新的一期【ASP.NET Core MVC开发实战之商城系统】已经开始,在之前的文章中,讲解了商城系统的整体功能设计,页面布局设计,环境搭建,系统配置,及首页【商品类型,banner条,友情链接,降价促销,新品爆款】,商品列表页面,商品详情等功能的开发,今天继续讲解购物车功能开发,仅供学习分享使用,如有不足之处,还请指正。
176 0
|
开发框架 前端开发 .NET
[回馈]ASP.NET Core MVC开发实战之商城系统(一)
[回馈]ASP.NET Core MVC开发实战之商城系统(一)
185 0