如何在 C# 中使用 Gecko

发布于 2024-12-26 02:56:24 字数 101 浏览 6 评论 0原文

我需要一个 Gecko WebBrowser 控件

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

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

I need a Gecko WebBrowser Control

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅浅 2025-01-02 02:56:24

编辑: (2023-11-6)

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


已过时:

2023 年 11 月 6 日:Gecko 的存储库为空。

带有详细快照的原始教程可以找到 这里


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

  • XulRunner:XULRunner 是一个 Mozilla 运行时包,可用于引导与 Firefox 和 Thunderbird 一样丰富的 XUL+XPCOM 应用程序。它提供了安装、升级和卸载这些应用程序的机制。 XULRunner 可以在此处下载。选择您喜欢的版本。

  • GeckoFx .net 程序集文件,您可以从此处下载该文件。
    还要选择与 XulRunner 版本匹配的正确版本。

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

在此处输入图像描述

  • 添加对 dll 的引用,如上所示,单击浏览并选择 Geckofx-Core.dll 并Geckofx-Winforms.dll

在此处输入图像描述
输入图片description here

  • 在工具箱中,右键单击,然后选择“Choose Item”,选择Geckofx-Winforms.dll,工具箱中就会显示Gecko winform控件

在此处输入图像描述
输入图片描述在这里

  • 将 GeckoWebBrowser 控件拖到 winform 设计器中,我们将其称为“浏览器”
    输入图片此处描述

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

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

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

在此处输入图像描述

Edit: (2023-11-6)

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


Outdated:

2023-11-6: Gecko's repo is empty.

Original tutorial with detailed snapshots can be found here.


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

  • 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:

enter image description here

  • Add references to the dlls as shown above, click browse and select the Geckofx-Core.dll and Geckofx-Winforms.dll

enter image description here
enter 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

enter image description here
enter 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

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

Now run the application, yeah~~~

enter image description here

荆棘i 2025-01-02 02:56:24

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

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

等数载,海棠开 2025-01-02 02:56:24

将gecko浏览器添加到Winform中。

简短:

  1. 通过nuget安装Geckox60.64

  2. 将项目设置为 x64

  3. 将其添加到 Program.cs:

 Xpcom.Initialize(“Firefox64”); 
  1. 将 geckowebbrowser 控件拖到您的表单中。

  2. 将其添加到 form1_load:

 geckoWebBrowser.Navigate(url); 

就是这样。


长:

  1. 在 Visual Studio 中创建一个新的 Winform 应用程序。目前我的版本是 VS 2019。

  2. 转到Nuget。搜索Geckofx。找到最新版本,即v60。

    安装Geckofx60.64

    完成此操作后,您将在项目中看到一些更改:

    • Winform 控件已添加到您的 UI 工具箱

    • DLL 列表将添加到您的 bin/[debug |release]/Firefox 文件夹

在此处输入图像描述

  1. 将 GeckoFX UI 控件拖到您的 Winform 设计器中,使其按照您希望的方式停靠:

在此处输入图像描述

  1. 您需要将此代码添加到 Program.cs:
 Xpcom.Initialize(“Firefox64”);

运行应用程序,它应该崩溃或弹出异常!

崩溃图片

  1. 要解决此问题,您需要为 x64 架构创建一个新的配置,如下所示:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

  1. 要在 GeckoFX 浏览器中打开 URL,请使用此功能:
 geckoWebBrowser.Navigate(url); 

重建并运行应用程序,万岁!成功了!

笔记:
他的回答已经过时了。从他的链接复制了这篇文章。

David Kou 的文章 , 示例GitHub 上的代码:

Add gecko browser into Winform.

Short:

  1. Install Geckofx60.64 via nuget

  2. set your project to x64

  3. add this to Program.cs:

 Xpcom.Initialize(“Firefox64”); 
  1. drag geckowebbrowser control to your form.

  2. add this to form1_load:

 geckoWebBrowser.Navigate(url); 

That's it.


Long:

  1. create a new Winform application in Visual Studio. Mine is VS 2019 as of now.

  2. Go to Nuget. search Geckofx. find the latest version, which is v60.

    Install Geckofx60.64

    Once this is done, you will see some changes in your project:

    • A Winform control is added to your UI Toolbox

    • A list of DLLs are added to your bin/[debug |release]/Firefox folder

enter image description here

  1. Drag a GeckoFX UI control to your Winform Designer, make it dock well as you wish:

enter image description here

  1. You need add this code to the Program.cs:
 Xpcom.Initialize(“Firefox64”);

Run the app, it should crash or pop up with an exception!

crash image

  1. To solve this, you need to create a new config for x64 architecture, like this:

enter image description here

enter image description here

enter image description here

  1. To open a Url in GeckoFX browser, use this function:
 geckoWebBrowser.Navigate(url); 

Rebuild and run the app, hooray! It worked!

Note:
His answer was outdated. Copied the article here, From his link.

Article by David Kou , Example code at GitHub:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文