开发者

Is there a way to programatically insert a Windows Forms control into an MSHTML (WebBrowser) instance?

I have an application that uses an embedded IE through th开发者_StackOverflowe 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


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜