Search
Text Attributes and Formatting

Text in Shape Nodes

A ShapeNode node can display Text within its outlines. Text position and alignment depend on the value of TextFormat. The text is painted with the color set in TextBrush. Even more useful layout and formatting attributes can be enabled via PolygonalTextLayout and EnableStyledText.

Layout Text in Arbitrary Shapes

ShapeNode instances can have various shapes, as specified through the Shape and ShapeOrientation properties. To layout text inside non-rectangular shapes, enable PolygonalTextLayout. If enabled, NetDiagram uses a formatting algorithm that fits exactly each line of text within the width of a line inside a polygonal shape. If a shape node has curved outlines, the formatting algorithm approximates them the polylines.

Text Wrapping

If there isn't enough space available to fit a whole line of text, NetDiagram wraps the text to a new line when it reaches the edge of the node. You can specify that the text should be wrapped only at word boundaries by setting the Trimming member of TextFormat to StringTrimming.Word. The default is to split words into multiple parts if there is not enough space to fit a whole word.

If you prefer to use your own line-breaks, you can disable the automatic text wrapping by enabling the NoWrap flag in the FormatFlags member of TextFormat. If automatic wrapping is disabled and there isn't enough space to fit the whole line, the text is clipped at the node boundaries.

Text in Tables

A TableNode can display text in its caption area and inside each cell. Text in the Caption is painted with CaptionBrush and is aligned as specified in CaptionFormat. Text in cells is painted in their own TextBrush and is aligned according to their own TextFormat. Even more useful formatting attributes can be enabled by the EnableStyledText property.

Styled Text

The ShapeNode.EnableStyledText property of shape nodes and the TableNode.EnableStyledText property of tables enables or disables styled text rendering. Styled text can have various attributes applied to the characters it contains. The attributes are specified using HTML-like formatting tags embedded in the raw text. Shape nodes can display styled text only if PolygonalTextLayout is enabled. Use the DrawStyledText method to display styled text in custom-drawn items.

The following table lists the currently supported style tags:

Tag 

Description

<i> text </i>

Indicates italic text.

<b> text </b> 

Indicates bold text.

<u> text </u>

Indicates underlined text.

<sub> text </sub> 

Indicates subscript.

<sup> text </sup> 

Indicates superscript.

<color=#RRGGBB> text </color> 

Changes the color of text; the red, green and blue color channel values are specified as hexadecimal numbers.

Links' text

The Text of a DiagramLink is painted with the color specified in TextBrush and is positioned as set in TextStyle.

Fonts

All items provide a Font property that allows getting or setting the font used for rendering their text. Always set the font's Unit property to World to get correct zooming of items' text and proper formatting and layout.