问题
I am trying to make GeckoWebBrowser
(version 45.0.34.0) control to work into my VB.NET project with no luck!!!
Here is the steps I follow...
1. I do right click on my project into Solution Explorer list and then Manage NuGet Packages.
2. I find and install Geckofx45.
3. Then I go into my Project's properties, into Compile tab and I change Target CPU to x86.
4. I Rebuild my project.
5. Then I add GeckoWebBrowser
control into my Toolbox by selecting the Geckofx-Winforms.dll file from ...\packages\Geckofx45.45.0.34\lib\net45
folder.
6. I add a GeckoWebBrowser
control into my form and just for test, I do GeckoWebBrowser1.Navigate("www.google.com")
into my form's Load
event.
7. I Start my app and I get nothing!!!
There is any step I miss or something?
回答1:
After an exhausting(!!!) research over the internet, I managed to make it work!!! Here is the steps for anyone who want to use GeckoWebBrowser to his/her VB.NET project.
1. Create a new VB.NET project or just open an existing one.
2. Go to menu Project and click on Manage NuGet Packages.
3. Click on Browse tab and search for Geckofx45.
4. Choose the one with description: library that allows embeding gecko in C# applications and click Install button.
5. Close NuGet window and go to your project's Properties.
6. Into Application tab click the View Application Events button.
7. Delete everything in there and paste this part of code and save it.
Imports Gecko
Imports System.IO
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 = My.Application.Info.DirectoryPath & "\Firefox\Profile"
If Not Directory.Exists(ProfileDirectory) Then
Directory.CreateDirectory(ProfileDirectory)
End If
Xpcom.ProfileDirectory = ProfileDirectory
Gecko.Xpcom.Initialize("Firefox")
Return True
End Function
End Class
End Namespace
8. Now, go back to your project Properties, click on Compile tab and set the Target CPU value to x86.
9. Build or Rebuild your project.
10a. To add GeckoWebBrowser
control into your Toolbox, first create a new Tab by then name GeckoFX 45 or whatever you like.
10b. Right click on it and click on Choose Items.
10b. Go into .NET Framework Componetns and click Browse button.
10c. Find Geckofx-Winforms.dll into your-project-folder\packages\Geckofx45.45.0.34\lib\net45\
and click Open button.
10d. Make sure that GeckoWebBrowser
is checked and then click OK.
回答2:
Probably one year too late here the variant for targeting x64:
Step 3 & 4: Embed GeckoFx 60
Step 7: Replace OnStartup function by:
Protected Overrides Function OnStartup(ByVal eventArgs As ApplicationServices.StartupEventArgs) As Boolean
Dim m_StartupPath As String = System.Windows.Forms.Application.StartupPath
Dim m_ProfileDirectory As String = System.IO.Path.Combine(m_StartupPath, "Firefox", "Profile")
If Not New System.IO.DirectoryInfo(m_ProfileDirectory).Exists Then System.IO.Directory.CreateDirectory(m_ProfileDirectory)
Xpcom.ProfileDirectory = m_ProfileDirectory
Dim m_BinDirectory As String = System.IO.Path.Combine(m_StartupPath, "Firefox64")
Xpcom.Initialize(m_BinDirectory)
Return True
End Function
Step 8: Target the project to x64
Steps 10a to 10d can be omitted.
来源:https://stackoverflow.com/questions/49407395/using-geckowebbrowser-v45-0-34-0-in-a-vb-net-project