Click here to Skip to main content
Click here to Skip to main content

Display HTML in your Application

, 23 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
A component that can parse and draw HTML/CSS in canvas
Screenshot - SmartTag.jpg


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.


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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Comments and Discussions

GeneralCool control, can you explain how to draw formated tex in sigle line Pinmemberrio_p12-Mar-10 2:22 
General"Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'QuickZip.MiniHtml.PropertyItemType'." PinmemberMember 29411441-Oct-09 9:04 
QuestionHow do i show image and use css to display image PinmemberVishnu Nath27-Mar-09 6:30 
GeneralAlternative control for rendering HTML in WinForms PinmemberWarwick Stock20-Nov-08 11:17 
QuestionrequiredHeight -- what about requiredWidth? [modified] Pinmemberjpe1-Nov-07 23:09 
AnswerRe: requiredHeight -- what about requiredWidth? Pinmemberjpe2-Nov-07 0:02 
General"GDI+'s measure width is very inaccurate" Pinmembergajatko24-Aug-07 4:13 
GeneralMaybe a better name is in order? (Nitpicking) PinmemberPIEBALDconsult23-Aug-07 14:59 
GeneralRe: Maybe a better name is in order? (Nitpicking) PinmemberLeung Yat Chun24-Aug-07 5:29 
GeneralCool Idea Pinmembermerlin98123-Aug-07 8:14 
GeneralInteresting PinmemberBoneSoft14-Aug-07 6:11 
GeneralAnother Question PinmemberDavidIPABD12-Aug-07 17:33 
GeneralRe: Another Question PinmemberLeung Yat Chun13-Aug-07 1:58 
GeneralRe: Another Question PinmemberDavidIPABD13-Aug-07 2:27 
GeneralRendering when minimized PinmemberDavidIPABD12-Aug-07 16:44 
GeneralRe: Rendering when minimized PinmemberLeung Yat Chun23-Aug-07 1:34 
GeneralAnchor tags around images PinmemberDavidIPABD12-Aug-07 16:14 
GeneralRe: Anchor tags around images PinmemberLeung Yat Chun23-Aug-07 1:55 
GeneralRe: Anchor tags around images PinmemberLeung Yat Chun23-Aug-07 1:58 
GeneralLicense PinmemberDavidIPABD12-Aug-07 15:53 
GeneralRe: License PinmemberLeung Yat Chun12-Aug-07 16:00 
GeneralIm watching this PinmemberDavidIPABD12-Aug-07 15:12 
GeneralRe: Im watching this PinmemberLeung Yat Chun12-Aug-07 16:11 
GeneralRich text editor Pinmembermo_kondori10-Aug-07 0:05 
GeneralRe: Rich text editor PinmemberLeung Yat Chun11-Aug-07 1:35 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150123.1 | Last Updated 23 Aug 2007
Article Copyright 2007 by Leung Yat Chun
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid