CEFSharp(铬嵌入式框架)的互操作用户控制 [英] CEFSharp (Chromium Embedded Framework) in Interop User Control

查看:2777
本文介绍了CEFSharp(铬嵌入式框架)的互操作用户控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用CefSharp CLR绑定铬嵌入式框架来创建一个替代的Web浏览器的控制,我们可以嵌入到仅支持以试图获得一些支持HTML5遗留ActiveX控件(Wonderware公司的InTouch HMI)应用程序对于一些reeaaallly老机器。

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.

到目前为止,我已经创建了使用的微软InteropForms工具包并嵌入一个CefSharp.WinForms的WebView到了pretty的裸机方式控制,即

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

当我生成DLL,我通过命令注册它

When I build the DLL, I register it via the command

regasm / TLB / codeBase的Cefsharp.WebControl.dll

regasm /tlb /codebase Cefsharp.WebControl.dll

这似乎工作的大部分,但我有一些问题,我不完全理解。我用VBA表格在Excel中测试它(纯粹是出于方便),当我使用窗体生成器,它实际上初始化时,它被添加到用户表单控件并加载网页完美:

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:

然而,当我尝试显示UseForm似乎要么销毁处理或web视图(或两者)的情况下,我不知道如何解决它。有一次,我尽量表现的形式和尝试像

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.

如果任何人有这个问题,我会非常AP preciate任何见解。谢谢!

If anyone has any insight on this, I'd greatly appreciate it. Thanks!

推荐答案

好吧,我想它了!我认为这部分是不得不做的处理,部分不得不做如何/当我初始化的WebView。我去的解决方案,最终采用CefSharp.Wpf,而不是Windows窗体,但它主要是相同的。主要的区别是增加对WebControl的设计器ElementHost控件初始化并创建新的WebView作为组件初始化的一部分:

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:

'Do not change this subroutine in the code editor. Use the designer.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Me.WebHost = New System.Windows.Forms.Integration.ElementHost()
    Me.SuspendLayout
    '
    'WebHost
    '
    Me.WebHost.Dock = System.Windows.Forms.DockStyle.Fill
    Me.WebHost.Location = New System.Drawing.Point(0, 0)
    Me.WebHost.Name = "WebHost"
    Me.WebHost.Size = New System.Drawing.Size(404, 244)
    Me.WebHost.TabIndex = 0
    Me.WebHost.Text = "WebHost"
    Me.WebHost.Child = New WebView(homepage, New CefSharp.BrowserSettings)
    '
    'WebControl
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.Controls.Add(Me.WebHost)
    Me.Name = "WebControl"
    Me.Size = New System.Drawing.Size(404, 244)
    Me.ResumeLayout(false)

End Sub

Friend WithEvents WebHost As System.Windows.Forms.Integration.ElementHost

这篇关于CEFSharp(铬嵌入式框架)的互操作用户控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆