0
votes

I'm working on a third party program called "Encompass 360" and I'm very confined to the limits of their SDK. With that said, they make use of MSHTML to draw up forms (hence why I can't utilize HAP.) This has been a very frustrating process.

I want to create my own form that is more dynamic than what they offer from their "form builder".

The definition they provide for us to use it:

public void AttachToDocument(HTMLDocument document, FormOptions option)

I'm trying this:

        HTMLDocument htpanel = pnlHTML.HTMLElement.document as HTMLDocument;
        htpanel.open();
        htpanel.createElement("Form");
        htpanel.createTextNode("Just some text");
        htpanel.createAttribute("P");
        htpanel.write(new object[] { "<P>Please work.</P>" });
        htpanel.close();
        htpanel.body.innerHTML = ("<SCRIPT type=\"text/javascript\">Alert(\"HI\");</SCRIPT>");
        try
        {
            htpanel.body.outerHTML = ("<BODY id=pnlHTML1 contentEditable=false style=\"BORDER-TOP: 0px inset; BORDER-RIGHT: 0px inset; BORDER-BOTTOM: 0px inset; BORDER-LEFT: 0px inset; VISIBILITY: inherit\" controlType=\"Class1\"></BODY>");
        }catch(Exception ex)
        {
            wf.MessageBox.Show(ex.Message.ToString());
        }
        htpanel.bgColor = Color.Black;
        this.Form.AttachToDocument(htpanel, FormOptions.None);

With the code above, "htpanel.write()" causes a COMException with the error of "Type Mismatch". I've tried many different ways I've found searching and can't get past this.

Can someone please point me in the right direction?

1

1 Answers

0
votes

The post Ryan linked (.net document write with mshtml) put me in the right direction. For Anyone else who may come down this path: I passed the control as an mshtml htmldocument to a different method which allowed the use of "IHTMLDocument2" and its .write method which actually works.

Code is below:

First method that assigns one of Encompass' controls as a true HTMLDocument,

        HTMLDocument htpanel = pnlHTML.HTMLElement.document as HTMLDocument;
        var add2form = doc(htpanel);
        this.Form.AttachToDocument(add2form, FormOptions.None);

Second method is what does the conversion and casts the control back.

       public HTMLDocument doc(HTMLDocument panel)
       {
        IHTMLDocument2 doc2 = (IHTMLDocument2)panel;
        doc2.bgColor = Color.Black;
        doc2.title = "my_title";
        doc2.write(new object[] { "<p>a</p>" });
        doc2.close();
        return (HTMLDocument)doc2;
       }

Thank you.