c# - How to obtain the Document Interface when Hosting the WebBrowser Control? -


please have @ following excellent article available on msdn

i in process of creating ie toolbar of bandobjects

i have access webbrowser control not able instantiate htmldocument require modify dom.

here excerpt of code:

// registering documentcomplete envent  explorer.documentcomplete += new shdocvw.dwebbrowserevents2_documentcompleteeventhandler(explorer_documentcomplete);  // not sure following function.  // trying suggested in msdn article -  // http://msdn.microsoft.com/en-us/library/aa752047%28v=vs.85%29.aspx#document  void explorer_documentcomplete(object pdisp, ref object url) {           ipersiststream pstream;         string htmltext = "<html><h1>stream test</h1><p>this html content being loaded stream.</html>";          htmldocumentclass document = (htmldocumentclass)this.explorer.iwebbrowser_document;         document.clear();         document.write(htmltext);         ihtmldocument2 document2 = (ihtmldocument2)pdisp;          pstream = (ipersiststream)document2.querycommandvalue("iid_ihtmldocument2");         htmldocument objdec = webbroswer.document;         objdec.write(htmltext); } 

you got bit lost in native ie object model. indeed makes bit painful load own html browser.

that's not problem if use webbrowser control. glue hidden in .net wrapper. super-simple, assign documenttext property. property setter takes care of hoopla. don't need documentcompleted event handler, collapses single line of code can put anywhere:

   webbrowser1.documenttext = "<h1>hello world</h1>"; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -