How to use Gecko in C#
Asked Answered
F

3

12

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

Frayda answered 8/1, 2012 at 14:26 Comment(2)
possible duplicate: #26647Variation
Your answer is in your tags. What's the problem?Variation
V
31

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

Vocalism answered 15/11, 2015 at 4:53 Comment(2)
Thank you very much for taking your time to write this answer, even though the question itself is a couple of years old...Broomstick
@Vocalism Thank you for quick and easy reference, during my implementation i am facing time out alerts for few sites. please refer the post if you can help me #63442447Meter
F
3

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

Fiona answered 8/1, 2012 at 15:12 Comment(0)
N
0

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:

Navarrette answered 5/11, 2023 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.