Class

# StyledText

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

## Description

Used to managed styled text independently of its display in a `TextArea</api/user_interface/desktop/desktoptextarea>`. For a `TextArea</api/user_interface/desktop/desktoptextarea>`, you can access the properties and methods of this class via the <span class="title-ref">StyledText</span> property of that class.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                          | Type                             | Read-Only | Shared |
|-------------------------------|----------------------------------|-----------|--------|
| `RTFData<styledtext.rtfdata>` | `String</api/data_types/string>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                        | Parameters                                                                                                                                                                  | Returns                            | Shared |
|-------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `AddStyleRun<styledtext.addstylerun>`                       | Run As `StyleRun</api/text/stylerun>`                                                                                                                                       |                                    |        |
| `AddStyleRunAt<styledtext.addstylerunat>`                   | index As `Integer</api/data_types/integer>`, run As `StyleRun</api/text/stylerun>`                                                                                          |                                    |        |
| `Bold<styledtext.bold>`                                     | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1                                                                               | `Boolean</api/data_types/boolean>` |        |
|                                                             | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>` |                                    |        |
| `FontName<styledtext.fontname>`                             | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>`                                                                                   | `String</api/data_types/string>`   |        |
|                                                             | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`   |                                    |        |
| `Italic<styledtext.italic>`                                 | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1                                                                               | `Boolean</api/data_types/boolean>` |        |
|                                                             | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>` |                                    |        |
| `Paragraph<styledtext.paragraph>`                           | Index As `Integer</api/data_types/integer>`                                                                                                                                 | `Paragraph</api/text/paragraph>`   |        |
| `ParagraphCount<styledtext.paragraphcount>`                 |                                                                                                                                                                             | `Integer</api/data_types/integer>` |        |
| `ParagraphTextAlignment<styledtext.paragraphtextalignment>` | Index As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `TextAlignments</api/text/textalignments>`                                           |                                    |        |
| `RemoveStyleRunAt<styledtext.removestylerunat>`             | Index As `Integer</api/data_types/integer>`                                                                                                                                 |                                    |        |
| `Size<styledtext.size>`                                     | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1                                                                               | `Single</api/data_types/single>`   |        |
|                                                             | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Single</api/data_types/single>`   |                                    |        |
| `StyleRun<styledtext.stylerun>`                             | Index As `Integer</api/data_types/integer>`                                                                                                                                 | `StyleRun</api/text/stylerun>`     |        |
| `StyleRunCount<styledtext.styleruncount>`                   |                                                                                                                                                                             | `Integer</api/data_types/integer>` |        |
| `StyleRunRange<styledtext.stylerunrange>`                   | Index As `Integer</api/data_types/integer>`                                                                                                                                 | `Range</api/text/range>`           |        |
| `Text<styledtext.text>`                                     |                                                                                                                                                                             | `String</api/data_types/string>`   |        |
| `TextColor<styledtext.textcolor>`                           | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1                                                                               | `Color</api/data_types/color>`     |        |
|                                                             | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Color</api/data_types/color>`     |                                    |        |
| `Underline<styledtext.underline>`                           | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1                                                                               | `Boolean</api/data_types/boolean>` |        |
|                                                             | Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>` |                                    |        |

## Property descriptions

<div id="styledtext.rtfdata">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.RTFData

**RTFData** As `String</api/data_types/string>`

> The styled text managed by the <span class="title-ref">StyledText</span> object in RTF format.
>
> This property supports cross-platform RTF generation and parsing. The RTF parser supports only the features found in the <span class="title-ref">StyledText</span> class.
>
> This example saves as RTF using the code snippet after the method that creates the StyleRuns.
>
> ``` xojo
> Var f As FolderItem = FolderItem.ShowSaveFileDialog(TextTypes.TextRtf, "TestSaveRTF")
>
> If f <> Nil Then
> Var s As TextOutputStream = TextOutputStream.Create(f)
> s.Write(TextArea1.StyledText.RTFData)
> s.Close
> End If
> ```

## Method descriptions

<div id="styledtext.addstylerun">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.AddStyleRun

**AddStyleRun**(Run As `StyleRun</api/text/stylerun>`)

> Adds the `StyleRun</api/text/stylerun>` passed to the end of *Text*.
>
> This example uses a `StyleRun</api/text/stylerun>` that is displayed in another `TextArea</api/user_interface/desktop/desktoptextarea>` and appends it to the <span class="title-ref">StyledText</span> that is displayed in another `TextArea</api/user_interface/desktop/desktoptextarea>`.
>
> ``` xojo
> TextArea2.StyledText.AddStyleRun(TextArea1.StyledText.StyleRun(0))
> ```

<div id="styledtext.addstylerunat">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.AddStyleRunAt

**AddStyleRunAt**(index As `Integer</api/data_types/integer>`, run As `StyleRun</api/text/stylerun>`)

> Adds the `StyleRun</api/text/stylerun>` passed at the insertion point designated by *index*.
>
> You can get the total number of StyleRuns in *Text* from the StyleRunCount method.
>
> This example appends a StyleRun into a `TextArea</api/user_interface/desktop/desktoptextarea>` and then inserts another one in an earlier position.
>
> ``` xojo
> TextArea2.StyledText.AddStyleRun(TextArea1.StyledText.StyleRun(1))
> TextArea2.StyledText.AddStyleRunAt(0, TextArea1.StyledText.Stylerun(0))
> ```

<div id="styledtext.bold">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.Bold

**Bold**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1) As `Boolean</api/data_types/boolean>`

> Gets the Bold style to the selected text in *Text*.
>
> *Start* is the starting position in *Text*. *Start* starts at zero. The default value for *Length* is 1. Returns a `Boolean</api/data_types/boolean>`.

**Bold**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>`)

> Sets the Bold style to the selected text in *Text*.
>
> *Start* is the starting position in *Text*. *Start* starts at zero. The default value for *Length* is 1.
>
> Bold some text in a TextArea:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
> TextArea1.StyledText.Bold(7, 5) = True ' "World" is now bold
> ```

<div id="styledtext.fontname">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.FontName

**FontName**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1) As `String</api/data_types/string>`

> Gets the font for the selected text in *Text*.
>
> *Start* is the starting position in *Text* (0-based). The default value for *Length* is 1. Returns a `String</api/data_types/string>`.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> On macOS, if Start + Length is greater than the Length of the String, then an `OutOfBoundsException</api/exceptions/outofboundsexception>` is raised. On other platforms, the change will apply to the end of the string.
>
> </div>

**FontName**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Sets the font for the selected text in *Text*.
>
> *Start* is the starting position in *Text* (0-based). The default value for *Length* is 1.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> On macOS, if Start + Length is greater than the Length of the String, then an `OutOfBoundsException</api/exceptions/outofboundsexception>` is raised. On other platforms, the change will apply to the end of the string.
>
> </div>
>
> Change the font for some text in a TextArea:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
> TextArea1.StyledText.FontName(7, 5) = "Courier"
> ```

<div id="styledtext.italic">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.Italic

**Italic**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1) As `Boolean</api/data_types/boolean>`

> Gets the Italic style to the selected text in *Text*.
>
> *Start* is the starting position in *Text*. The default value for *Length* is 1. Returns a `Boolean</api/data_types/boolean>`.

**Italic**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>`)

> Sets the Italic style to the selected text in *Text*.
>
> *Start* is the starting position in *Text*. *Start* starts at zero. The default value for *Length* is 1.
>
> Italic some text in a TextArea:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
> TextArea1.StyledText.Italic(7, 5) = True ' "World" is now italic
> ```

<div id="styledtext.paragraph">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.Paragraph

**Paragraph**(Index As `Integer</api/data_types/integer>`) As `Paragraph</api/text/paragraph>`

> Returns as a `Paragraph</api/text/paragraph>` the paragraph in *Text* indicated by *Index*.
>
> The properties of the `Paragraph</api/text/paragraph>` class enable you to access its position and alignment.

<div id="styledtext.paragraphcount">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.ParagraphCount

**ParagraphCount** As `Integer</api/data_types/integer>`

> Returns as an `Integer</api/data_types/integer>` the number of paragraphs in *Text*.
>
> Completely empty paragraphs (e.g., blank lines) do not count as paragraphs.

<div id="styledtext.paragraphtextalignment">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.ParagraphTextAlignment

**ParagraphTextAlignment**(Index As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `TextAlignments</api/text/textalignments>`)

> Aligns the paragraph indicated by *Index*.
>
> Assign an alignment to ParagraphTextAlignment using one of the `TextAlignments</api/text/textalignments>` values.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> Not supported with Linux TextFields.
>
> </div>

<div id="styledtext.removestylerunat">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.RemoveStyleRunAt

**RemoveStyleRunAt**(Index As `Integer</api/data_types/integer>`)

> Removes the `StyleRun</api/text/stylerun>` indicated by *Index*.
>
> You can get the total number of StyleRuns in *Text* from the StyleRunCount method.
>
> This example removes StyleRun 3.
>
> ``` xojo
> TextArea1.StyledText.RemoveStyleRunAt(3)
> ```

<div id="styledtext.size">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.Size

**Size**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1) As `Single</api/data_types/single>`

> Gets the font size for the selected text in *Text*.
>
> *Start* is the starting position in *Text*. The default value for *Length* is 1. Returns a `Single</api/data_types/single>`.

**Size**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Single</api/data_types/single>`)

> Sets the font size for the selected text in *Text*.
>
> *Start* is the starting position in *Text*. The default value for *Length* is 1.
>
> Change size of text in a TextArea:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
> TextArea1.StyledText.Size(7, 5) = 32 ' "World" is now 32 point
> ```

<div id="styledtext.stylerun">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.StyleRun

**StyleRun**(Index As `Integer</api/data_types/integer>`) As `StyleRun</api/text/stylerun>`

> Returns a `StyleRun</api/text/stylerun>` specified by *Index*. *Index* is zero-based.

<div id="styledtext.styleruncount">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.StyleRunCount

**StyleRunCount** As `Integer</api/data_types/integer>`

> Returns as an `Integer</api/data_types/integer>` the number of style runs in *Text*.
>
> Use this in conjunction with the StyleRun and StyleRunRange methods to get information about each style run.

<div id="styledtext.stylerunrange">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.StyleRunRange

**StyleRunRange**(Index As `Integer</api/data_types/integer>`) As `Range</api/text/range>`

> Returns a `Range</api/text/range>` for the specified `StyleRun</api/text/stylerun>`. *Index* is zero-based.
>
> Properties of the `Range</api/text/range>` class give you access to the `StyleRun</api/text/stylerun>`'s starting and ending positions, and length.
>
> The following example loops through the `StyleRuns</api/text/stylerun>` in a block of <span class="title-ref">StyledText</span> that is displayed in a `TextArea</api/user_interface/desktop/desktoptextarea>`. It uses the StartPos and Length properties of the Range class to get the position of each `StyleRun</api/text/stylerun>` and displays it and the text of each `StyleRun</api/text/stylerun>` in a `ListBox</api/user_interface/desktop/desktoplistbox>`.
>
> ``` xojo
> Var count As Integer = TextArea1.StyledText.StyleRunCount ' get the number of StyleRuns
>
> For i As Integer = 0 To count - 1  ' loop through them
> ListBox1.AddRow(TextArea1.StyledText.StyleRunRange(i).StartPos.ToString)
> ListBox1.CellTextAt(i, 1) = TextArea1.StyledText.StyleRunRange(i).Length.ToString
> ListBox1.CellTextAt(i, 2) = TextArea1.StyledText.StyleRun(i).Text
> Next
> ```

<div id="styledtext.text">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.Text

**Text** As `String</api/data_types/string>`

> The text whose style attributes are managed via the instance of this class.
>
> The *Start* and *Index* parameters of the methods of this class are zero-based and referenced from the start of *Text*. Set the value of *Text* using the assignment operator.
>
> Setting the Text property clears any previously set style information. If you want to modify text inline without changing the style you will need to use the `StyleRuns</api/text/stylerun>`, adding and removing them as necessary.
>
> Add some styled text to a TextArea:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
> TextArea1.StyledText.Bold(7, 5) = True ' "World" is now bold
> ```

<div id="styledtext.textcolor">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.TextColor

**TextColor**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1) As `Color</api/data_types/color>`

> Gets or sets the text color for the selected text in *Text*.
>
> *Start* is the starting position in *Text*. The default value for *Length* is 1. Returns a `Color</api/data_types/color>`.

**TextColor**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Color</api/data_types/color>`)

> Sets the text color for the selected text in *Text*.
>
> *Start* is the starting position in *Text*. The default value for *Length* is 1.
>
> Bold some text in a TextArea:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
> TextArea1.StyledText.TextColor(7, 5) = &cff0000 ' "World" is now red
> ```

<div id="styledtext.underline">

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

</div>

<div class="rst-class">

forsearch

</div>

StyledText.Underline

**Underline**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1) As `Boolean</api/data_types/boolean>`

> Gets the Underline style to the selected text in *Text*.
>
> *Start* is the starting position in *Text*. The default value for *Length* is 1. Returns a `Boolean</api/data_types/boolean>`.

**Underline**(Start As `Integer</api/data_types/integer>`, Length As `Integer</api/data_types/integer>` = 1, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>`)

> Sets the Underline style to the selected text in *Text*.
>
> *Start* is the starting position in *Text*. The default value for *Length* is 1.
>
> Underline some text in a TextArea:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
> TextArea1.StyledText.Underline(7, 5) = True ' "World" is now underline
> ```

## Notes

The <span class="title-ref">StyledText</span> class enables you to apply style attributes to the <span class="title-ref">StyledText</span> class. This means that obtaining a `StyleRun</api/text/stylerun>` (using StyleRun()) and setting the style attributes for that run will not be reflected in the `TextArea</api/user_interface/desktop/desktoptextarea>`. To operate on a `StyleRun</api/text/stylerun>`, you must remove the old run and replace it with the new run. The preferred way to do it would be to make changes using the <span class="title-ref">StyledText</span> methods instead of the `StyleRun</api/text/stylerun>` properties.

Because the `TextArea</api/user_interface/desktop/desktoptextarea>` already has selection style attributes, the <span class="title-ref">StyledText</span> class honors that information. This means that you can set the style information using the selection methods that are available within the `TextArea</api/user_interface/desktop/desktoptextarea>` class, and they will be reflected when getting `StyleRun</api/text/stylerun>` information (and vice versa).

## Sample code

The following example uses the methods of the <span class="title-ref">StyledText</span> class to mark up and align text and display it in a `TextArea</api/user_interface/desktop/desktoptextarea>`. In order for the styled text to display, you must turn on the Multiline and Styled properties of the `TextArea</api/user_interface/desktop/desktoptextarea>` (both are on by default).

``` xojo
Var txt As String ' text to be displayed in TextArea
Var st, ln As Integer ' start and length values of a paragraph

' define four paragraphs in Text
txt = "This is the text that we are going to save " _
  + "into our file from the TextArea." + EndOfLine _
  + "Isn't that interesting?" + EndOfLine _
  + "Man, I sure do love using Xojo to take care of my projects."

TextArea1.StyledText.Text = txt ' four paragraphs in Text
TextArea1.StyledText.Bold(5, 2) = True
TextArea1.StyledText.TextColor(5, 2) = &cFF0000 ' bold and red
TextArea1.StyledText.Size(7, 10) = 16
TextArea1.StyledText.Underline(12, 4) = True ' 16 pt underline
TextArea1.StyledText.Size(100, 4) = 18
TextArea1.StyledText.TextColor(100, 4) = &cFF00FF ' 18 pt and Magenta
TextArea1.StyledText.Font(0, txt.Length) = "Comic Sans MS"

' center align second paragraph
TextArea1.StyledText.ParagraphTextAlignment(1) = TextAlignments.Center

' set this paragraph in Helvetica, 18 pt bold, red
' first get the start and length values for this paragraph...
st = TextArea1.StyledText.Paragraph(1).StartPosition
ln = TextArea1.StyledText.Paragraph(1).Length + 1

' next apply attributes...
TextArea1.StyledText.Bold(st, ln) = True
TextArea1.StyledText.Font(st, ln) = "Helvetica"
TextArea1.StyledText.Size(st, ln) = 18
TextArea1.StyledText.TextColor(st, ln) = &cFF0000
```

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

The resulting text area looks like this:

> ![image](images/styledtext_styled_text_output.png)

The following code, added to the end of the previous method, saves the styled text to disk in RTF format. It assumes that the File Type Set, "TextTypes" has one item, TextRTF, that defines the RTF file type.

``` xojo
Var f As FolderItem = FolderItem.ShowSaveFileDialog(TextTypes.TextRtf, "TestSaveRTF")

If f <> Nil Then
  Var s As TextOutputStream = TextOutputStream.Create(f)
  s.Write(TextArea1.StyledText.RTFData)
End If
```

## Compatibility

|                       |                       |
|-----------------------|-----------------------|
| **Project Types**     | Console, Desktop, Web |
| **Operating Systems** | All                   |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `Paragraph</api/text/paragraph>`, `Range</api/text/range>`, `StyleRun</api/text/stylerun>`, `DesktopTextArea</api/user_interface/desktop/desktoptextarea>` classes.

</div>
