Format Multiline Text

New text automatically assumes the characteristics of the current text style. The STANDARD text style is the default. You can override the default text style by applying formatting to individual characters and applying properties to the Text object. You also can indicate formatting or special characters using the methods described in this section.

Orientation options such as style, justification, width, and rotation affect all text within the mtext text boundary, not specific words or characters. Use the AttachmentPoint property to change the justification of mtext, and the Rotation property to control the angle of rotation of the text boundary.

The StyleName property sets the default fonts and formatting characteristics for new text. As you create text, you can select which style you want to use from a list of existing styles. When you change the style of an MText object that has character formatting applied to any portion of the text, the style is applied to the entire object, and some formatting of characters might not be retained. For instance, changing from a TrueType style to a style using an SHX font or to another TrueType font causes the text to use the new font for the entire object, and any character formatting is lost.

Formatting options such as underlining, stacked text, or fonts can be applied to individual words or characters within a paragraph. You also can change color, font, and text height. You can change the spaces between text characters or increase the width of the characters.

Use curly braces ({ }) to apply a format change only to the text within the braces. You can nest braces up to eight levels deep.

You also can enter the ASCII equivalent for control codes within lines or paragraphs to indicate formatting or special characters, such as tolerance or dimensioning symbols.

The following control characters can be used to create the text in the illustration. (For the ASCII equivalent of this string see the example following the illustration.)

{{\H1.5x; Big text} \A2; over text\A1;/\A0; under text}

For more information about formatting multiline text, see “Format Characters Within Multiline Text” in the User's Guide.

Use control characters to format text

This example creates and formats an MText object.

Sub Ch4_FormatMText()
	Dim mtextObj As AcadMText
	Dim insertPoint(0 To 2) As Double
	Dim width As Double
	Dim textString As String

	insertPoint(0) = 2
	insertPoint(1) = 2
	insertPoint(2) = 0
	width = 4

	' Define the ASCII characters for the control characters
	Dim OB As Long  ' Open Bracket  {
	Dim CB As Long  ' Close Bracket }
	Dim BS As Long  ' Back Slash	\
	Dim FS As Long  ' Forward Slash /
	Dim SC As Long  ' Semicolon	 ;
	OB = Asc("{")
	CB = Asc("}")
	BS = Asc("\")
	FS = Asc("/")
	SC = Asc(";")

	' Assign the text string the following line of control
	' characters and text characters:
	' {{\H1.5x; Big text}\A2; over text\A1;/\A0; under text}

	textString = Chr(OB) + Chr(OB) + Chr(BS) + "H1.5x" _
	+ Chr(SC) + "Big text" + Chr(CB) + Chr(BS) + "A2" _
	+ Chr(SC) + "over text" + Chr(BS) + "A1" + Chr(SC) _
	+ Chr(FS) + Chr(BS) + "A0" + Chr(SC) + "under text" _
	+ Chr(CB)

	' Create a text Object in model space
	Set mtextObj = ThisDrawing.ModelSpace. _
			 AddMText(insertPoint, width, textString)
End Sub