Click here to Skip to main content
15,887,262 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 control, can you explain how to draw formated tex in sigle line Pin
ripsware12-Mar-10 1:22
ripsware12-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
Member 29411441-Oct-09 8:04 
QuestionHow do i show image and use css to display image Pin
Vishnu Nath27-Mar-09 5:30
Vishnu Nath27-Mar-09 5:30 
GeneralAlternative control for rendering HTML in WinForms Pin
Warwick Stock20-Nov-08 10:17
Warwick Stock20-Nov-08 10:17 
QuestionrequiredHeight -- what about requiredWidth? [modified] Pin
jpe1-Nov-07 22:09
jpe1-Nov-07 22:09 
AnswerRe: requiredHeight -- what about requiredWidth? Pin
jpe1-Nov-07 23:02
jpe1-Nov-07 23:02 
General"GDI+'s measure width is very inaccurate" Pin
Lutosław24-Aug-07 3:13
Lutosław24-Aug-07 3:13 
GeneralMaybe a better name is in order? (Nitpicking) Pin
PIEBALDconsult23-Aug-07 13:59
mvePIEBALDconsult23-Aug-07 13:59 
GeneralRe: Maybe a better name is in order? (Nitpicking) Pin
Leung Yat Chun24-Aug-07 4:29
Leung Yat Chun24-Aug-07 4:29 
GeneralCool Idea Pin
merlin98123-Aug-07 7:14
professionalmerlin98123-Aug-07 7:14 
GeneralInteresting Pin
BoneSoft14-Aug-07 5:11
BoneSoft14-Aug-07 5:11 
GeneralAnother Question Pin
DavidIPABD12-Aug-07 16:33
DavidIPABD12-Aug-07 16:33 
GeneralRe: Another Question Pin
Leung Yat Chun13-Aug-07 0:58
Leung Yat Chun13-Aug-07 0:58 
GeneralRe: Another Question Pin
DavidIPABD13-Aug-07 1:27
DavidIPABD13-Aug-07 1:27 
GeneralRendering when minimized Pin
DavidIPABD12-Aug-07 15:44
DavidIPABD12-Aug-07 15:44 
GeneralRe: Rendering when minimized Pin
Leung Yat Chun23-Aug-07 0:34
Leung Yat Chun23-Aug-07 0:34 
GeneralAnchor tags around images Pin
DavidIPABD12-Aug-07 15:14
DavidIPABD12-Aug-07 15:14 
GeneralRe: Anchor tags around images Pin
Leung Yat Chun23-Aug-07 0:55
Leung Yat Chun23-Aug-07 0:55 
GeneralRe: Anchor tags around images Pin
Leung Yat Chun23-Aug-07 0:58
Leung Yat Chun23-Aug-07 0:58 
GeneralLicense Pin
DavidIPABD12-Aug-07 14:53
DavidIPABD12-Aug-07 14:53 
GeneralRe: License Pin
Leung Yat Chun12-Aug-07 15:00
Leung Yat Chun12-Aug-07 15:00 
You can use, I will update the license in next update, and add the following :

-------------------------

The library is released under the GPL with the following exception:

Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination.

As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.

Bottom line In plain English this means you can use this library in commercial closed-source applications.

-------------------------


GeneralIm watching this Pin
DavidIPABD12-Aug-07 14:12
DavidIPABD12-Aug-07 14:12 
GeneralRe: Im watching this Pin
Leung Yat Chun12-Aug-07 15:11
Leung Yat Chun12-Aug-07 15:11 
GeneralRich text editor Pin
mo_kondori9-Aug-07 23:05
mo_kondori9-Aug-07 23:05 
GeneralRe: Rich text editor Pin
Leung Yat Chun11-Aug-07 0:35
Leung Yat Chun11-Aug-07 0:35 

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.