I am trying to use the CefSharp CLR bindings for the Chromium Embedded Framework to create an alternative web browser control that we can embed into an application that only supports legacy ActiveX controls (WonderWare InTouch HMI) in an attempt to gain some HTML5 support for some reeaaallly old machines.
So far, I've created an Interop User Control using the Microsoft InteropForms Toolkit and embedded a CefSharp.WinForms WebView onto the control in a pretty bare-bones manner, i.e.
Private Sub WebControl_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim Settings = New CefSharp.Settings
If (CEF.Initialize(Settings)) Then
WebView = New WebView(homepage, New BrowserSettings())
WebView.Dock = DockStyle.Fill
End If
Me.Controls.Add(WebView)
End Sub
When I build the DLL, I register it via the command
regasm /tlb /codebase Cefsharp.WebControl.dll
This seems to work for the most part, but I am having some issues that I do not fully understand. I am testing it with the VBA Forms in Excel (purely out of convenience) and when I am using the Form Builder, it actually initializes the control when it is added to the user form and loads the webpage perfectly:
However, when I try to show the UseForm it seems to either destroy the handle or the instance of the webview (or both) and I can't figure out how to fix it. Once I try to show the form and try something like
Sub Test()
WebForm.Show
WebForm.WebControl.Navigate "www.google.com"
End Sub
I get an error that the object doesn't exist. I've messed around a bit and sometimes I get different errors like the pointer is invalid but so far I haven't figured out how to set it up properly. I think it is a problem with handling the User Form events, but I am not sure.
If anyone has any insight on this, I'd greatly appreciate it. Thanks!
Okay, I figured it out! I think it partly had to do with the handler and partly had to do with how/when I was initializing the webview. The solution I went with ended up using the CefSharp.Wpf instead of the Windows Form, but it's mostly the same. The main difference is adding the initialization of an ElementHost control on the WebControl Designer and create the new WebView as part of the component initialization: