如何在 C# 中使用 Gecko

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8778320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 04:23:44  来源:igfitidea点击:

How to use Gecko in C#

c#geckogeckofxgeckosdk

提问by DanMatlin

I need a Gecko WebBrowser Control

我需要一个 Gecko WebBrowser 控件

I need a sample code or a link which explains how to use GECKO

我需要一个示例代码或一个解释如何使用 GECKO 的链接

If anyone has used Gecko, I could do with some advice

如果有人用过 Gecko,我可以提供一些建议

回答by Johnny Graber

You should check out http://code.google.com/p/geckofx/. To get some code samples see the Wiki page.

您应该查看http://code.google.com/p/geckofx/。要获取一些代码示例,请参阅Wiki 页面

回答by David

Original tutorial with detailed snapshots can be found here.

可以在此处找到带有详细快照的原始教程。

A most recent update can be found here. Please upvote in that article if you find it useful :)

可以在此处找到最新更新。如果您觉得有用,请在该文章中点赞 :)

To embed Gecko browser in your winform application, you need:

要将 Gecko 浏览器嵌入到您的 winform 应用程序中,您需要:

  • XulRunner: XULRunner is a Mozilla runtime package that can be used to bootstrap XUL+XPCOM applications that are as rich as Firefox and Thunderbird. It provides mechanisms for installing, upgrading, and uninstalling these applications. XULRunner can be downloaded here. Choose the version you like.
  • GeckoFx .net assembly file, which you can download from here. Also choose the correct version which matches the XulRunner version.

  • Unpack the GeckoFX-330.zip, you will get below files:

  • XulRunner:XULRunner 是一个 Mozilla 运行时包,可用于引导与 Firefox 和 Thunderbird 一样丰富的 XUL+XPCOM 应用程序。它提供了安装、升级和卸载这些应用程序的机制。XULRunner 可以在这里下载。选择你喜欢的版本。
  • GeckoFx .net 程序集文件,您可以从这里下载。还要选择与 XulRunner 版本匹配的正确版本。

  • 解压 GeckoFX-330.zip,你会得到以下文件:

enter image description here

在此处输入图片说明

  • Add references to the dlls as shown above, click browse and select the Geckofx-Core.dll and Geckofx-Winforms.dll
  • 添加对 dll 的引用,如上所示,单击浏览并选择 Geckofx-Core.dll 和 Geckofx-Winforms.dll

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

  • In the toolbox, right click, and then select “Choose Item”, select Geckofx-Winforms.dll, and the Gecko winform control will be shown in the toolbox
  • 在工具箱中右击,然后选择“Choose Item”,选择Geckofx-Winforms.dll,工具箱中就会出现Gecko winform控件

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

  • Drag a GeckoWebBrowser control to the winform designer, and let's call it “browser” enter image description here

  • In the form1.cs file, add below code: enter image description here

  • 拖一个 GeckoWebBrowser 控件到 winform 设计器,我们称它为“浏览器” 在此处输入图片说明

  • 在 form1.cs 文件中,添加以下代码: 在此处输入图片说明

The line Gecko.Xpcom.Initialize(@”..\xulrunner”); specifies where the xulrunner runtime is located. In this case, we put it into a folder (@”..\xulrunner”).

行 Gecko.Xpcom.Initialize(@"..\xulrunner"); 指定 xulrunner 运行时所在的位置。在本例中,我们将其放入一个文件夹(@”..\xulrunner”)。

Now run the application, yeah~~~

现在运行应用程序,是的~~~

enter image description here

在此处输入图片说明