WebBrowser Control

  • Thread starter Thread starter Pete Davis
  • Start date Start date
P

Pete Davis

Write the string out to a .txt file and then set the URL to that, is one
way.

Pete
 
How can I display a string representation of a html
document using a WebBrowser control on a windows form as
opposed to passing an URL to the Navigate method?
 
In this case you have to right click on your Toolbox -> Add/Remove Items ->
Com Components Tab -> Find Microsoft Web Browser Control -> Checkmark it ->
Okay -> then go to your toolbox and scroll down if needed and drag the
Microsoft web browser (earth icon) onto your form.

You will also need to add several references. Project -> Referenes -> Com
tab ->

Find Microsoft HTML Object Library and double click on it

You might also need a reference to AxBrowser. (It's been a while since i've
actually created this project).

In your References it should have an AxSHDocVW and or ShDocVw and
Microsoft.mshtml

Microsoft.mshtml C:\Program Files\Microsoft.NET\Primary Interop
Assemblies\Microsoft.mshtml.dll



Use this following code to set the InnerHTML value. The only thing to note
is that images and css and such will not be loaded. If you are familiar with
Javascript and CSS PreLaoders/Switchers you can use the same method if CSs
is vital to the case. But the below sample takes XML and an XSLT file and
returns HTML and sets the body's innerHTML to the HTML

The following is for C# but should be adaptable for almost any .NET langauge
easily.





AxSHDocVw - (may be added automatically)

// Get Web Browser Document

mshtml.IHTMLDocument2 tmppc = (mshtml.IHTMLDocument2)
axWebBrowser1.Document;

// Peform XSLT Transfomration

string tmpText =
xslt_Transformation(tmpXMLDoc, @"demoXSLTTemplate.xslt");

// Update Textboxes and Internet control

txtXMLView.Text = tmpXMLDoc.InnerXml;
// Text

txtHTMLView.Text = tmpText;
// Text

tmppc.body.innerHTML = tmpText;
// HTML



Hope this helps
 
Back
Top