Click here to Skip to main content
15,887,311 members
Articles / Multimedia / GDI+
Article

Display HTML in your Application

Rate me:
Please Sign up or sign in to vote.
4.57/5 (8 votes)
23 Aug 2007CPOL1 min read 83.3K   2K   81   26
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder
Hong Kong Hong Kong

Comments and Discussions

 
Generalcool Pin
Bahrudin Hrnjica9-Aug-07 11:19
professionalBahrudin Hrnjica9-Aug-07 11:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.