Viewin HTML in Winform application

G

Guest

I am looking for a way to view HTML in Winform application. Does anyone know if there is something like a browser control that I could use to render the HTML?

Thanks,
Serge.
 
S

Sahil Malik

Yeh that'll work, but you get a real heavy duty axWebBrowser control ..
kinda like killing a fly with a hammer .. but if you must use that .. here
is sample code to render a "text" to a webbrowser control -

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using mshtml;

namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{
private AxSHDocVw.AxWebBrowser browser;
private System.ComponentModel.Container components = null;


public Form1()
{
InitializeComponent();
string url = "about:blank";
object o = System.Reflection.Missing.Value;
browser.Navigate ( url,ref o,ref o,ref o,ref o);

AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler handler =
new
AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler
(this.browser_StatusTextChange);
browser.StatusTextChange += handler;
}



private void browser_StatusTextChange
(object sender,
AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e)
{


mshtml.HTMLDocument doc =
(mshtml.HTMLDocument)this.browser.Document;
doc.body.innerHTML = "<H1>foo</H1>";
}


protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


#region Windows Form Designer generated code


private void InitializeComponent()
{
System.Resources.ResourceManager resources = new

System.Resources.ResourceManager(typeof(Form1));
this.browser = new AxSHDocVw.AxWebBrowser();

((System.ComponentModel.ISupportInitialize)(this.browser)).BeginInit();
this.SuspendLayout();
//
// browser
//
this.browser.Enabled = true;
this.browser.Location = new System.Drawing.Point(16,
16);
this.browser.OcxState =


((System.Windows.Forms.AxHost.State)(resources.GetObject("browser.OcxState")
));
this.browser.Size = new System.Drawing.Size(344,
224);
this.browser.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5,
13);
this.ClientSize = new System.Drawing.Size(392, 302);
this.Controls.AddRange(new
System.Windows.Forms.Control[] {
this.browser});
this.Name = "Form1";
this.Text = "Form1";

((System.ComponentModel.ISupportInitialize)(this.browser)).EndInit();
this.ResumeLayout(false);


}
#endregion


[STAThread]
static void Main()
{
Application.Run(new Form1());
}


}
}
 
G

Guest

Go to the Form Designer and right-click on the top of the Windows Forms
section of the tools list and click on Add/Remove Items...

Go to the COM Components page and check the "Microsoft Web Browser".

Then go to the bottom of the list of items under Windows Forms and drag the
web browser onto your form.

It's a COM component, but it's wrapper up very nicely. Take a look at the
documentation for IWebBrowser2 to find out how to manipulate it, but for the
most part, you treat it like a .NET component.

Do a google search on axWebBrowser and you'll find some sample code. I know
there are a few on Code Project.

Pete

Serge said:
I am looking for a way to view HTML in Winform application. Does anyone
know if there is something like a browser control that I could use to render
the HTML?
 
G

Guest

Thanks for suggestions,
It seems that this sample creats the .rtf format, what I am looking is to be able to display an HTML page that is an aggregate of several HTML documents that are dynamically contcatenated into a one page (as if it is some kind of a report). When user selects one of the buttons on a panel on the left, the panel on the right that hosts the HTML page should be able to scroll to the correct portion of the HTML report. It seems that I might be able to do this using the Browser ActiveX control.

Serge.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top