Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Display HTML in your Application

0.00/5 (No votes)
23 Aug 2007 1  
A component that can parse and draw HTML/CSS in canvas
Screenshot - SmartTag.jpg

Introduction

This component is a pure C# component which can parse HTML syntax and draw it.

Using the Code

Just drop the component (mhLabel) on your form, and specify HTML and CSS.

I do not have a list of supported HTML and CSS tags yet. Please check the following if you need a list:

  • HTML - Defines.cs (line 129)
  • CSS - MiniCss.cs (line 26)

If you wish to develop your own component, you can take a look to Controls \ Label.cs for a sample.

Points of Interest

This component is very simple. HTML syntax is converted to tags. Every tag (e.g. bold) is an object. Each of them can change the environment in some way, like changing the CurrentState object, allocate space from parent tag.

I port this component from my Delphi component. Because this is my first C# component, I encountered many problems, one of them is that the GDI+'s measure width is very inaccurate. I have to estimate the true width (e.g. TextWidth - 2) when positioning the texts. Now I know Graphics.MeasureCharacterRanges, but I still don't understand why they don't make TextWidth return the true width. (btw, MeasureCharacterRanges does not support CF).

Screenshot - testsize.jpg

It's much more accurate now.

History

  • 09-08-2007: Initial release
  • 23-08-2007: License update, image link support, bgcolor support for [p] tag

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here