Windows Forms: How to use GeckoFx Web Browser in C#

This post shows you How to use GeckoFx Web Browser in C# Windows Forms Application.

Gecko is a web browser allows you to integrate into your desktop application.

Creating a new form that allows you to enter a url, then navigate to the website where you entered the url.

c# geckofx

Next, Right-click on your project, then select Manage Nuget Packages from the Visual Studio =>Search 'geckofx'=>Download and install it.

geckofx c#

After finishing installing the library into your project, you need to right-click on your project, then select Properties =>Build =>Select your platform target as x86, then rebuild your project.

Opening your form designer, then drag the geckofx from your Visual Studio toolbox to your form designer.

Adding the below line to your constructor.

Xpcom.Initialize("Firefox");

Adding a load event handler to your form allows you to navigate to the url.

private void frmGeckofxBrowser_Load(object sender, EventArgs e)
{
    txtUrl.Text = "https://foxlearn.com";
    geckoWebBrowser1.Navigate(txtUrl.Text);
}

Adding a keypress event handler to the TextBox control allows you to enter key, then navigate to the url.

private void txtUrl_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
        geckoWebBrowser1.Navigate(txtUrl.Text);
}

Gecko is a library that allows embeding gecko in C# applications.