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:

黄聪:在.NET中使用GeckoFX 29的更多相关文章

  1. 黄聪:AngularJS中的$resource使用与Restful资源交互(转)

    原文:http://blog.csdn.net/he90227/article/details/50525836 1.AngularJS中的 $resource 这个服务可以创建一个资源对象,我们可以 ...

  2. 转载: 黄聪:C#中 Excel列字母与数字的转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. 黄聪:C#中HtmlAgilityPack判断是否包含或不包含指定的属性或值

    //选择不包含class属性的节点 var result = node.SelectNodes(".//span[not(@class)]"); //选择不包含class和id属性 ...

  4. 黄聪:HtmlAgilityPack中SelectSingleNode的XPath和CSS选择器

    XPath和CSS选择器 原文:http://ejohn.org/blog/xpath-css-selectors 最近,我做了很多工作来实现一个同时支持XPath和CSS 3的解析器,令我惊讶的是: ...

  5. 黄聪:wordpress中PHP运行错最有效解决办法Fatal error: Out of memory (allocated 6029312)(转)

    近日在升级wordpress 3.2.1和若干插件的过程中,发现了一个wordpress的错误:Allowed memory size of XXX bytes exhausted Fatal err ...

  6. 黄聪:C#中CefSharp的简单使用

    C#中CefSharp的简单使用 https://blog.csdn.net/qq_26712977/article/details/78282995

  7. 黄聪:bootstrap中模态框modal在苹果手机上会失效

    bootstrap中模态框在苹果手机上会失效 可将代码修改为<a  data-toggle="modal" data-target="#wrap" hre ...

  8. 黄聪:C#中WebClient自动判断编码是UTF-8还是GBK,并且有超时判断功能

    public class WebDownload : WebClient { private int _timeout; /// <summary> /// 超时时间(毫秒) /// &l ...

  9. 黄聪:wordpress中remove_action、add_action、 do_action()的hook钩子都有哪些

    原文地址:http://codex.wordpress.org/Plugin_API/Action_Reference muplugins_loaded After must-use plugins ...

随机推荐

  1. ss linux终端配置

    最近ss莫名宕机,懒得重新安装了,就安装了一个非gui版本,安装非gui版本还有一个优点就是在远程服务器的时候可以用proxychains进行终端代理,非常友好实用.下面简单的说一下如何进行终端ss ...

  2. Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

    Struts Problem Report Struts has detected an unhandled exception: Messages: Write operations are not ...

  3. es6 set&sort

    es6提供了新的数据结构Set. 它类似于数组,但是成员的值都是唯一的,没有重复的值. Set函数可以接受一个数组(或类似数组的对象)作为参数,用来初始化. 1.set去重 首先我们 let 一个数组 ...

  4. FTP相关、用vsftpd搭建ftp、xshell使用xftp传输文件、使用pure-ftpd搭建ftp服务

    1.FTP相关(file transfer protocol,文件传输协议)   2.用vsftpd搭建ftp安装:yum install vsftpd -y创建一个虚拟用户:useradd  vft ...

  5. PTA——最大公约数和最小公倍数

    PTA 7-26 最大公约数和最小公倍数 #include<stdio.h> int main(){ int num1,num2,temp1,temp2,r; scanf("%d ...

  6. freemarker的template用法

    package cn.itcast.ssm.util; import com.alibaba.fastjson.JSONObject; import freemarker.cache.StringTe ...

  7. cglib实现动态代理简单使用

    Boss: package proxy.cglib; public class Boss{ public void findPerson() { System.out.println("我要 ...

  8. Java 枚举(enum) 详解4种常见的用法

    JDK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. 大师兄我又加上自己的理解,来帮助各位理解一下. 用法一:常量 在JDK1.5 之前,我们定义常 ...

  9. 【java编程】格式化字符串

    String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. form ...

  10. LOJ3048 「十二省联考 2019」异或粽子

    题意 题目描述 小粽是一个喜欢吃粽子的好孩子.今天她在家里自己做起了粽子. 小粽面前有 $n$ 种互不相同的粽子馅儿,小粽将它们摆放为了一排,并从左至右编号为 $1$ 到 $n$.第 $i$ 种馅儿具 ...