Posted my piece of code to embed the IE WebBrowser control in .NET without wrapping DLL's [.NET] as a GDN User Sample In general it is a rework of the code posted here, but with some extensions I needed and without saving static html to temporary file to navigate to later. The crux of matter is how to define the correct Interop for IHTMLDocument2.Write(). Here is my working solution:
IHTMLDocument2.Write()
using System; using System.Runtime.InteropServices;
namespace System.Windows.Forms.Html { [InterfaceType(ComInterfaceType.InterfaceIsDual), ComVisible(true), Guid(@"332C4425-26CB-11D0-B483-00C04FD90119")] interface IHTMLDocument2 { ... /// /// Write complete html doc content including markup. /// /// object[] containing the string(s) /// /// /// IHTMLDocument2 document = control.GetDocument(); /// if (document != null) { /// document.Open("", null, null, null); /// object[] a = new object[]{"Hello world"}; /// document.Write(a); /// document.Close(); /// } /// /// void Write( [In, MarshalAs(UnmanagedType.SafeArray)] object[] psarray); ... }}
/// IHTMLDocument2 document = control.GetDocument(); /// if (document != null) { /// document.Open("", null, null, null); /// object[] a = new object[]{"Hello world"}; /// document.Write(a); /// document.Close(); /// } ///
May be there is an Interop Guy that is able to solve it in a more elegant way? Currently IJW. This functionality is covered by the control itself. Usage of that feature of IE Control looks like this:
htmlControl.Html = myHtmlString;htmlControl.Navigate(null);
With this approach you will also get the NavigateXYZ() events to listen for further usage.
© Copyright 2002-2012, Torsten Rendelmann Page rendered at Wednesday, February 08, 2012 7:31:30 AM (W. Europe Standard Time, UTC+01:00)
Like RSS Bandit? Make a donation to help support its development and maintenance. As little as 1€ will help.
SUBSCRIBE RSS GeoURL
newtelligence dasBlog 2.3.9074.18820
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.