Class

# Paragraph

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

## Description

A <span class="title-ref">Paragraph</span> of `StyledText</api/text/styledtext>`.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                     | Type                                       | Read-Only | Shared |
|------------------------------------------|--------------------------------------------|-----------|--------|
| `EndPosition<paragraph.endposition>`     | `Integer</api/data_types/integer>`         | ✓         |        |
| `Length<paragraph.length>`               | `Integer</api/data_types/integer>`         |           |        |
| `StartPosition<paragraph.startposition>` | `Integer</api/data_types/integer>`         |           |        |
| `TextAlignment<paragraph.textalignment>` | `TextAlignments</api/text/textalignments>` |           |        |

## Property descriptions

<div id="paragraph.endposition">

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

</div>

<div class="rst-class">

forsearch

</div>

Paragraph.EndPosition

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

> End position of the <span class="title-ref">Paragraph</span> (1-based).
>
> This property is read-only.
>
> Bold the last character of the text:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
>
> ' Bold the "!"
> Var theEnd As Integer = TextArea1.StyledText.Paragraph(1).EndPosition
> TextArea1.StyledText.Bold(theEnd - 1, 1) = True
> ```

<div id="paragraph.length">

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

</div>

<div class="rst-class">

forsearch

</div>

Paragraph.Length

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

> Length (in characters) of the <span class="title-ref">Paragraph</span>.
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
>
> ' Bold the text
> Var len As Integer = TextArea1.StyledText.Paragraph(1).Length
> TextArea1.StyledText.Bold(0, len) = True
> ```

<div id="paragraph.startposition">

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

</div>

<div class="rst-class">

forsearch

</div>

Paragraph.StartPosition

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

> The starting position of the <span class="title-ref">Paragraph</span>.
>
> Bold the first character of the \`Paragraph\`:
>
> ``` xojo
> TextArea1.StyledText.Text = "Hello, World!"
>
> ' Bold the first character
> Var first As Integer = TextArea1.StyledText.Paragraph(1).StartPosition
> TextArea1.StyledText.Bold(first, 1) = True
> ```

<div id="paragraph.textalignment">

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

</div>

<div class="rst-class">

forsearch

</div>

Paragraph.TextAlignment

**TextAlignment** As `TextAlignment</api/text/textalignments>`

> Gets the text alignment of the <span class="title-ref">Paragraph</span>.
>
> The values of this property are set using the `TextAlignments</api/text/textalignments>` enumeration.
>
> To set the alignment of a <span class="title-ref">Paragraph</span>, call the ParagraphAlignment method of the `StyledText</api/text/styledtext>` class. You can use the <span class="title-ref">Paragraph</span> or the `TextField</api/user_interface/desktop/desktoptextfield>` alignment constants to set a <span class="title-ref">Paragraph</span> alignment using the ParagraphAlignment method.
>
> This is an example of a right-aligned first <span class="title-ref">Paragraph</span>.
>
> ``` xojo
> Var st As New StyledText
> st = TextArea1.StyledText
> TextArea1.AddText("This is the added text.")
> st.Bold(0, 4) = True
> st.Paragraph(0).TextAlignment = TextAlignments.Right
> ```

## Notes

Use the <span class="title-ref">Paragraph</span> class to refer to a <span class="title-ref">Paragraph</span> of text within a block of `StyledText</api/text/styledtext>`. A <span class="title-ref">Paragraph</span> is defined as all the text between two <span class="title-ref">Paragraph</span> separators. A separator can be the `EndOfLine</api/text/endofline>` function or the correct separator character for the platform on which the application is running. Completely empty paragraphs (e.g., blank lines) do not count as paragraphs.

You use the `ParagraphCount<styledtext.paragraphcount>` method of the `StyledText</api/text/styledtext>` class to get the number of paragraphs in the `StyledText</api/text/styledtext>` object and the `Paragraph<styledtext.paragraph>` method of the `StyledText</api/text/styledtext>` class to refer to a particular <span class="title-ref">Paragraph</span>.

The <span class="title-ref">Paragraph</span> has one style attribute, `TextAlignment<paragraph.textalignment>`. It gets the current alignment for the <span class="title-ref">Paragraph</span>. The alignment is set by calling the `StyledText.ParagraphTextAlignment<styledtext.paragraphtextalignment>` method of the `StyledText</api/text/styledtext>` class.

## Sample code

The following example sets a <span class="title-ref">Paragraph</span>'s alignment to Centered. It then gets the starting position and length of the <span class="title-ref">Paragraph</span> via the <span class="title-ref">Paragraph</span> class and applies several style attributes to the whole <span class="title-ref">Paragraph</span>. The `TextArea</api/user_interface/desktop/desktoptextarea>` that displays the styled text must have the MultiLine and Styled properties set to `True</api/language/true>`.

``` xojo
Var Text As String
Var st, ln As Integer

' define four paragraphs in Text
Text = "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." + EndOfLine _
  + "That's because the Xojo staff is just so awesome!"
TextArea1.StyledText.Text = text  ' four paragraphs in Text

' center the second paragraph
TextArea1.StyledText.Paragraph(1).TextAlignment = TextAlignments.Center

' set the second paragraph in Helvetica, 18 pt bold, red
' first get its character positions...
st = TextArea1.StyledText.Paragraph(1).StartPosition
ln = TextArea1.StyledText.Paragraph(1).Length

' 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 ' red
```

## Compatibility

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

<div class="seealso">

`Range</api/text/range>` parent class; `DesktopTextArea</api/user_interface/desktop/desktoptextarea>`, `Range</api/text/range>`, `StyledText</api/text/styledtext>`, `StyleRun</api/text/stylerun>` classes.

</div>
