Click here to Skip to main content
11,704,473 members (51,276 online)
Click here to Skip to main content

Display HTML in your Application

, 23 Aug 2007 CPOL 57.2K 1.6K 79
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author


You may also be interested in...

Comments and Discussions

 
GeneralCool control, can you explain how to draw formated tex in sigle line Pin
rio_p12-Mar-10 1:22
memberrio_p12-Mar-10 1:22 
General"Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'QuickZip.MiniHtml.PropertyItemType'." Pin
Member 29411441-Oct-09 8:04
memberMember 29411441-Oct-09 8:04 
QuestionHow do i show image and use css to display image Pin
Vishnu Nath27-Mar-09 5:30
memberVishnu Nath27-Mar-09 5:30 
GeneralAlternative control for rendering HTML in WinForms Pin
Warwick Stock20-Nov-08 10:17
memberWarwick Stock20-Nov-08 10:17 
QuestionrequiredHeight -- what about requiredWidth? [modified] Pin
jpe1-Nov-07 22:09
memberjpe1-Nov-07 22:09 
AnswerRe: requiredHeight -- what about requiredWidth? Pin
jpe1-Nov-07 23:02
memberjpe1-Nov-07 23:02 
General"GDI+'s measure width is very inaccurate" Pin
gajatko24-Aug-07 3:13
membergajatko24-Aug-07 3:13 
GeneralMaybe a better name is in order? (Nitpicking) Pin
PIEBALDconsult23-Aug-07 13:59
memberPIEBALDconsult23-Aug-07 13:59 
GeneralRe: Maybe a better name is in order? (Nitpicking) Pin
Leung Yat Chun24-Aug-07 4:29
memberLeung Yat Chun24-Aug-07 4:29 
GeneralCool Idea Pin
merlin98123-Aug-07 7:14
membermerlin98123-Aug-07 7:14 
GeneralInteresting Pin
BoneSoft14-Aug-07 5:11
memberBoneSoft14-Aug-07 5:11 
GeneralAnother Question Pin
DavidIPABD12-Aug-07 16:33
memberDavidIPABD12-Aug-07 16:33 
GeneralRe: Another Question Pin
Leung Yat Chun13-Aug-07 0:58
memberLeung Yat Chun13-Aug-07 0:58 
GeneralRe: Another Question Pin
DavidIPABD13-Aug-07 1:27
memberDavidIPABD13-Aug-07 1:27 
GeneralRendering when minimized Pin
DavidIPABD12-Aug-07 15:44
memberDavidIPABD12-Aug-07 15:44 
GeneralRe: Rendering when minimized Pin
Leung Yat Chun23-Aug-07 0:34
memberLeung Yat Chun23-Aug-07 0:34 
GeneralAnchor tags around images Pin
DavidIPABD12-Aug-07 15:14
memberDavidIPABD12-Aug-07 15:14 
GeneralRe: Anchor tags around images Pin
Leung Yat Chun23-Aug-07 0:55
memberLeung Yat Chun23-Aug-07 0:55 
GeneralRe: Anchor tags around images Pin
Leung Yat Chun23-Aug-07 0:58
memberLeung Yat Chun23-Aug-07 0:58 
GeneralLicense Pin
DavidIPABD12-Aug-07 14:53
memberDavidIPABD12-Aug-07 14:53 
GeneralRe: License Pin
Leung Yat Chun12-Aug-07 15:00
memberLeung Yat Chun12-Aug-07 15:00 
GeneralIm watching this Pin
DavidIPABD12-Aug-07 14:12
memberDavidIPABD12-Aug-07 14:12 
GeneralRe: Im watching this Pin
Leung Yat Chun12-Aug-07 15:11
memberLeung Yat Chun12-Aug-07 15:11 
GeneralRich text editor Pin
mo_kondori9-Aug-07 23:05
membermo_kondori9-Aug-07 23:05 
GeneralRe: Rich text editor Pin
Leung Yat Chun11-Aug-07 0:35
memberLeung Yat Chun11-Aug-07 0: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
Web01 | 2.8.150819.1 | Last Updated 23 Aug 2007
Article Copyright 2007 by Leung Yat Chun
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid