/// <summary> /// Creates a new instance of HtmlDocument class and initializes its content to /// specified string /// </summary> public static HtmlDocument CreateHtmlDocument(string content) { if (content == null) { content = ""; } Assembly winforms = typeof(Form).Assembly; //System.Windows.Forms //создадим служебный класс HtmlShimManager Type t = winforms.GetType("System.Windows.Forms.HtmlShimManager"); object obj = Activator.CreateInstance(t, true); //создадим документ и загрузим в него пустую строку var doc = new HTMLDocument(); IHTMLDocument2 doc2 = (IHTMLDocument2)doc; doc2.Write(new object[] { content }); doc2.Close(); HtmlDocument htmldoc = null; //создаем HtmlDocument с помощью закрытого конструктора htmldoc = (HtmlDocument)Activator.CreateInstance( typeof(HtmlDocument), BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { obj, doc }, System.Globalization.CultureInfo.InvariantCulture); return(htmldoc); }
// called from SelfNavigateComplete() protected void SetHtmlText(string text) { if (text == null) { text = String.Empty; } if (!IsHandleCreated) { return; } if (control != null) { IHTMLDocument2 document = control.Document; if (document != null) { if (activate) { DoVerb(Interop.OLEIVERB_UIACTIVATE); } // this way we can provide the FULL HTML incl. <head><style> etc. document.Open("", null, null, null); object[] a = new object[] { text }; document.Write(a); document.Close(); _document = document; // Without the "Refresh" command, the browser control doesn't // react to links containing the # character in the hyperlink. try { if (text.IndexOf("#") > 0) { document.ExecCommand("Refresh", false, null); } } catch {} } } }