Previous Page
Next Page

Recipe 9.8. Displaying HTML-Formatted Text

Problem

You want to display HTML content in a text field.

Solution

Set the text field's htmlText property to the value of the HTML content to display.

Discussion

Text fields can interpret and display basic HTML tags, if properly configured. Using HTML in a text field is a convenient way to add hyperlinks and simple formatting, such as font color and bolded text.

The value of the text field object's htmlText property is interpreted as HTML:

field.htmlText = "<u>This displays as underlined text.</u>";

No matter what, the text property of a text field is rendered as plain text. This means that even if the text property is set to <u>test</u>, the object displays <u>test</u> instead of test. That means that if you want to display HTML code in its unrendered format assign the HTML value to the text property of the text field, as follows:

field.text = "<u>underlined text</u>";

/* text field displays:
<u>underlined text</u>
*/

This can be a useful technique if, for example, you want to show both the rendered HTML and the HTML source code in side-by-side text fields:

htmlCode = "<i>italicized text</i>";
sourceHTML.text = htmlCode;
renderedHTML.htmlText = htmlCode;

You cannot display both rendered and unrendered HTML in the same text field. If you try, you will end up with unreliable results.

The set of HTML tags supported by text fields includes: <b>, <i>, <u>, <font> (with face, size, and color attributes), <p>, < br>, <a >, <li>, <img>, and <textformat> (with leftmargin, rightmargin, blockindent, indent, leading, and tabstops attributes corresponding to the TextFormat class's properties of the same names).


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)