Thursday, January 22, 2009

Access HTML content in windows application.

We might be much habituated in building web applications, such that it could be more efficient in providing information to user in interface (windows application) could be friendlier while using html content than setting text to each individual windows component.

I would like to display a table that has some styles.
In that case I may not replicate exactly using windows applications.
So, if we prepare a html content using required styles and can use that content to display required information.
Windows provides a component called “web browser”, we can just just drag and drop the component onto windows form.

Now I refer this web browser object as “objBrowser”, and use this object to display the html content that I prepare.
HTML content I am willing to display is a table with some style applied to it.
<table cellpadding=’0’ cellspacing=’0’ border=’0’ align=’center’>
<tr style=’border: 1px solid #618773;’><td>Hi</td><td> Friends</td></tr>
<tr style=’border: 1px solid #618773;’><td colspan=’2’>Welcome to my blog</td></tr>
Windows form

Code file

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Learnings
public partial class Browser : Form
public Browser()

private void Browser_Load(object sender, EventArgs e)
string strContent = "<table cellpadding=’0’ cellspacing=’0’ border=’0’ align=’center’><tr style=’border: 1px solid #618773;’><td>Hi</td><td> Friends</td></tr><tr style=’border: 1px solid #618773;’><td colspan=’2’>Welcome to my blog</td></tr></table>";
objBrowser.DocumentText = strContent;

No comments:

Post a Comment