分享

.net winform程序下使用firefox作为Web浏览器

 昵称597197 2016-06-17

在winform程序中,要在程序中展示一个web页面,最常用的就是.net自带的webbrowser,但是大家都知道它是IE,也知道IE是有多么强(er)大(bi)。而且微软已经宣布了IE的死亡。

 

那么如何使用firefox呢?只需两步:

1、添加引用:Geckofx-Core、Geckofx-Winforms;图1

2、把xulrunner放在你项目的bin目录下;图2

  图1

  图2

上面两个资源的下载地址:https:///geckofx/geckofx-33.0/downloads

ftp://ftp.mozilla.org/pub/xulrunner/releases/33.0/runtimes/

但是要注意一点:geckofx的版本要和xulrunner的版本对应,不然会有问题。xulrunner是firefox官网提供的,有最新版本,但是geckofx版本相对落后一些,但是也更新到了33.0版本,对应firefox的发布时间是2014年10月份,应该也够用了。

 

当把前面的资源配置好后,接下来就是调用api的活了,非常简单,上一段简单的代码。

新建一个winform程序,然后在默认的form1.cs文件中加入以下代码。

复制代码
 1     public partial class Form1 : Form
 2     {
 3         private readonly string xulrunnerPath = Application.StartupPath + "/xulrunner";
 4         private const string testUrl = "https://www.alipay.com/";  
 5         private GeckoWebBrowser Browser; 
 6         public Form1()
 7         {
 8             InitializeComponent();
 9 
10             Xpcom.Initialize(xulrunnerPath);
11 
12             
13         }
14 
15         private void Form1_Load(object sender, EventArgs e)
16         {
17             Browser = new GeckoWebBrowser();
18             Browser.Parent = this;
19             Browser.Dock = DockStyle.Fill;
20             Browser.Navigate(testUrl);  
21         }
22     }
复制代码

OK,运行项目你将会看到支付宝的首页。


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多