Apr 23, 2011 11:51 AM
(This post was last modified: Jun 15, 2011 08:52 PM by eXero.)
The Implementation of GeckoFX
This tutorial is going to show you how to implement GeckoFX (the web browser control) into your own VB.NET program so that you don't have to use the hated default IE one. Let's begin.
What you need:
- GeckoFX files - Download
- XUL Runner Files - Download
- VB.NET Project Already Coded - Download
-NOTE: XP SP3 and IE7/8 have an error not mentioned in the tutorial because it was written in Win7. It has to do with your operating system. Sorry!
Step 1.
Open up your new VB.NET project and name it whatever you would like. Now put a menustrip in your project, and name the first one Start, and the second one Exit.
Spoiler (Click to View)
Save the project whatever you like.
Step 2.
Put the entire xulrunner folder after it is extracted into the debug folder also. Make sure all the xulrunner files are one level into the xulrunner folder.
Spoiler (Click to View)
Step 3.
In Solution Explorer, right click on your project name and click "Add Reference". Click "Browse" and navigate to where you put Skybound.Gecko.dll. Click it. Click okay.
Spoiler (Click to View)
Step 4.
Put the following code in Form1:
Code
'**
'* *
'* Author: RK *
'* Example provider: ident *
'* *
'* Contact: [email protected] *
'* *
'* DESCRIPTION *
'* *
'* Implements Gecko engine. *
'* *
'**
Option Strict On
Public Class MainForm
Private Sub StartToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartToolStripMenuItem.Click
MessageBox.Show("Give it a few seconds to load up the webpage.")
GeckoWebBrowser1.Navigate("https://hackforums.net")
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Dispose()
End Sub
End Class
'IMPLENTATION NOTES:
'
' 1) http://en.wikipedia.org/wiki/Gecko_%28layout_engine%29
' 2) http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/Step 5.
In your project toolbox you should see GeckoWebBrowser at the bottom of all your tools. Drag it onto your project. Set it's dock to "Fill".
Spoiler (Click to View)
Step 6.
In Solution Explorer, right click and then click on "Add". Add a Code File named "Application Events.vb."
Spoiler (Click to View)
Step 7.
Add the following code to ApplicationEvents.vb:
Code
Imports System.IO
Imports Skybound.Gecko
Namespace My
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Protected Overrides Function OnStartup(ByVal eventArgs As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) As Boolean
Dim ProfileDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\xulrunner\DefaultProfile"
If Not Directory.Exists(ProfileDirectory) Then
Directory.CreateDirectory(ProfileDirectory)
End If
Xpcom.ProfileDirectory = ProfileDirectory
Dim xrPath As String = System.Reflection.Assembly.GetExecutingAssembly.Location
xrPath = xrPath.Substring(0, xrPath.LastIndexOf("\") + 1) & "\xulrunner"
Xpcom.Initialize(xrPath)
Return True
End Function
End Class
End NamespaceSpoiler (Click to View)
Step 8.
Debug the project. It should work perfectly now.
Spoiler (Click to View)
Step 9.
Post a reply on this thread what you thought of my tutorial! I put a lot of time and effort into writing this trying to help you figure out how to implement GeckoFX into your VB.NET application. The least you can do is post a reply that takes a few seconds to write in order to keep the thread alive. Credit for this tutorial goes to me, eXero. Ident helped with some things. Thank you for reading!


