有没有办法以编程方式将 Windows 窗体控件插入 MSHTML (WebBrowser) 实例?
我有一个通过 Windows 窗体 WebBrowser 控件使用嵌入式 IE 的应用程序。我想将一些 .NET 控件嵌入到 HTML 页面中。
旧有支持(自 .NET 1.0 起)在
是否有其他方法可以将 .NET 控件(可能是 UserControl 子类)添加到加载到嵌入式 IE 实例中的现有 html 页面?
我可以在 .NET 中编写适当的 ActiveX 控件并使用无注册表 COM 来让 IE 实例化它吗?我似乎记得一些关于 MS 提供支持以逐步启用 VB 迁移的文章,但我找不到任何内容。
围绕 MSHTML 的其他问题似乎意味着几乎不可能改变其内置行为,因此我的希望很小,这意味着如果有人有解决方案,我会非常高兴。
/P
I have an application that uses an embedded IE through the Windows Forms WebBrowser control. I want to embed some .NET controls into the HTML page.
There is old support (since .NET 1.0) to use a special classid in an <object> tag (dllname#controlname) but through experimentation I have found that it only works if the dll is served over http so it's not possible for me to use.
Is there any other way to add a .NET control (probably a UserControl subclass) to an existing html page loaded into the embedded IE instance?
Could I write a proper ActiveX control in .NET and use registry-less COM to get IE to instantiate it? I seem to remember some article about MS providing support for this to enable VB migration step-by-step but I can't find anything.
Other questions around MSHTML seem to imply that it's almost impossible to change its built-in behavior so I have very little hope which means that I'd be very happy if anyone has a solution.
/P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 Microsoft Interop Forms Toolkit 2.1 进行了测试,该工具包可以创建可作为 OCX(可见 ActiveX 控件)嵌入的 UserControl。事实证明,注册表写入是必要的,因为托管 COM 组件无法设置使用免注册表 COM 嵌入所需的 OCX 标志(这些标志仅适用于本机 COM)。
以编程方式将“object”标记添加到 C# mshtml 主机中的 mshtml 后,我可以访问 HtmlObject 实例及其 @object 属性,以访问托管 UserControl 子类并添加其他子控件。
哦,我确保在 32 位和 64 位部分都注册了控件。
唯一仍然困扰我的是对注册表的依赖......
I tested using the Microsoft Interop Forms Toolkit 2.1 which made it possible to create a UserControl that could be embedded as an OCX (visible ActiveX control). Registry writing turned out to be necessary since managed COM components cannot set the OCX flags needed for embedding using registry-free COM (these flags are only available for native COM).
After programmatically adding an "object" tag to mshtml in the C# mshtml host, I could get to the HtmlObject instance and its @object property to get to the managed UserControl subclass and add additional child controls.
Oh, and I made sure to register the control both in the 32-bit and 64-bit parts.
The only thing that still bothers me is the dependency on the registry...