Back to Devexpress

DevExpress Presentation API Library: Work with Shape Text

officefileapi-405581-presentation-api-slides-work-with-shape-text.md

latest24.4 KB
Original Source

DevExpress Presentation API Library: Work with Shape Text

  • Feb 24, 2026
  • 10 minutes to read

The Presentation API library allows you to manage text content inside shapes. This help topic explains how you can add and access shape text, format paragraphs, and change font settings.

Add and Format Shape Text

Use the shape’s Shape.TextArea property to specify the shape text and configure text settings.

To specify the text area content, add TextParagraph objects to the TextArea.Paragraphs collection. To split a paragraph into runs (spans of text that share the same formatting), add TextRun objects to the TextParagraph.Runs collection.

A new shape’s text area initially contains one default empty paragraph to keep the presentation document valid. This paragraph goes first in the TextArea.Paragraphs collection.

The following example adds a shape with two paragraphs and configures text settings:

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...

        Shape shape = new Shape(ShapeType.Rectangle);
        shape.Outline = new OutlineStyle { Fill = new SolidFill(Color.RoyalBlue), Width = 4 };

        TextArea textArea = new TextArea();
        textArea.Paragraphs.Clear(); // Removes the default paragraph.
        TextParagraph paragraph1 = new TextParagraph();
        paragraph1.Runs.Add(new TextRun ("5 "));
        paragraph1.Runs.Add(new TextRun {
            Text = "successful",
            TextProperties = new TextProperties {
                Fill = new SolidFill(Color.Green),
                FontSize = 22,
                UnderlineFill = new SolidFill(Color.Black),
                UnderlineType = TextUnderlineType.HeavyDotDotDash,
                UnderlineStyle = new UnderlineStyle(new OutlineStyle { Fill = new SolidFill(Color.Red), Width = 2 }),

            }
        });
        paragraph1.Runs.Add(new TextRun (" builds"));
        textArea.Paragraphs.Add(paragraph1);

        TextParagraph paragraph2 = new TextParagraph();
        paragraph2.Runs.Add(new TextRun ("2 failed builds"));
        paragraph2.Properties = new ParagraphProperties() {
            SpacingBefore = new TextSpacing(TextSpacingType.Point, 30),
            ListBulletColor = new TextBulletColor(new OfficeColor(Color.Red)),
            ListBullet = new CharListBullet('■'),
            ListBulletSize = new TextBulletSize(TextBulletSizeType.Point, 30)
        };
        textArea.Paragraphs.Add(paragraph2);
        shape.TextArea = textArea;

        shape.X = 30;
        shape.Y = 30;
        shape.Width = 800;
        shape.Height = 400;

        slide.Shapes.Add(shape);
    }
}
vb
Imports DevExpress.Docs.Presentation
Imports System.Drawing

Namespace PresentationApiSample

    Public Class Program
        Public Shared Sub Main(__ As String())
            ' ...
            Dim shape As Shape = New Shape(ShapeType.Rectangle)
            shape.Outline = New OutlineStyle With {
                    .Fill = New SolidFill(Color.RoyalBlue),
                    .Width = 4
                }

            Dim textArea As TextArea = New TextArea()
            textArea.Paragraphs.Clear() ' Removes the default paragraph.
            Dim paragraph1 As TextParagraph = New TextParagraph()
            paragraph1.Runs.Add(New TextRun("5 "))
            paragraph1.Runs.Add(New TextRun With {
                .Text = "successful",
                .TextProperties = New TextProperties With {
                    .Fill = New SolidFill(Color.Green),
                    .FontSize = 22,
                    .UnderlineFill = New SolidFill(Color.Black),
                    .UnderlineType = TextUnderlineType.HeavyDotDotDash,
                    .UnderlineStyle = New UnderlineStyle(New OutlineStyle With {
                            .Fill = New SolidFill(Color.Red),
                            .Width = 2
                        })

                }
            })
            paragraph1.Runs.Add(New TextRun(" builds"))
            textArea.Paragraphs.Add(paragraph1)

            Dim paragraph2 As TextParagraph = New TextParagraph()
            paragraph2.Runs.Add(New TextRun("2 failed builds"))
            paragraph2.Properties = New ParagraphProperties() With {
                .SpacingBefore = New TextSpacing(TextSpacingType.Point, 30),
                .ListBulletColor = New TextBulletColor(New OfficeColor(Color.Red)),
                .ListBullet = New CharListBullet("■"c),
                .ListBulletSize = New TextBulletSize(TextBulletSizeType.Point, 30)
            }
            textArea.Paragraphs.Add(paragraph2)
            shape.TextArea = textArea

            shape.X = 30
            shape.Y = 30
            shape.Width = 800
            shape.Height = 400

            slide.Shapes.Add(shape)
        End Sub
    End Class
End Namespace

You can also use TextArea.Text, TextParagraph.Text, and TextRun.Text properties to specify text content. Use the “\r\n” character sequence to split the string value into paragraphs or runs.

csharp
shape.TextArea = new TextArea() { Text = "Paragraph 1\r\nParagraph 2\r\nParagraph 3" };
vb
shape.TextArea = New TextArea() With {
        .Text = "Paragraph 1" & vbCrLf & "Paragraph 2" & vbCrLf & "Paragraph 3"
    }

You can specify paragraph layout settings such as paragraph indents. Use TextAreaBase.ParagraphProperties to share settings across all shape paragraphs or TextParagraph.Properties to configure settings at the paragraph level.

Note: Different presentation viewers may prioritize text styles differently and use either TextAreaBase.ParagraphProperties or TextAreaBase.Level1ParagraphProperties to display top-level text.

Configure Numbering

Use the shape.TextArea.ParagraphProperties.ListBullet property to add a bullet symbol to a paragraph and display the paragraph as a bulleted list item. The following bullet types are available:

CharListBulletUses a UTF-16 character as a bullet. For example: • (U+2022), ▪ (U+25AA) or ➤ (U+27A4). You can pass a bullet symbol in the CharListBullet constructor.ImageListBulletUses an image as a bullet. Specify the ImageListBullet.Image property to set a bullet image.NumberingListBulletAllows you to create an autonumbering list. Use the NumberingListBullet.StartNumber property to specify from which number or symbol the numbering starts. To format bullets, use the NumberingListBullet.Format property.

All bullet types have the following customization options in common:

csharp
using DevExpress.Docs;
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        Presentation presentation = new Presentation();
        presentation.Slides.Clear();

        Slide slide = new Slide(SlideLayoutType.Blank);
        presentation.Slides.Add(slide);

        Shape shape = new Shape(ShapeType.Rectangle, 30, 30, 2000, 1000);
        slide.Shapes.Add(shape);

        // Use a numbering bullet for a text paragraph
        NumberingListBullet n_bullet = new NumberingListBullet(NumberingListBulletFormat.WideBlackCircledNumber, 1);
        TextParagraph paragraph1 = new TextParagraph();
        paragraph1.Properties.ListBullet = n_bullet;
        paragraph1.Text = "Paragraph 1";
        shape.TextArea.Paragraphs.Add(paragraph1);

        // Use an image bullet for a text paragraph
        Stream stream = new FileStream(@"..\..\..\data\image.png", FileMode.Open, FileAccess.Read);
        ImageListBullet i_bullet = new ImageListBullet { Image = new OfficeImage(DXImage.FromStream(stream)) };
        TextParagraph paragraph2 = new TextParagraph();
        paragraph2.Properties.ListBullet = i_bullet;
        paragraph2.Text = "Paragraph 2";
        shape.TextArea.Paragraphs.Add(paragraph2);

        // Use a char bullet for a text paragraph
        CharListBullet c_bullet = new CharListBullet('•');
        TextParagraph paragraph3 = new TextParagraph();
        paragraph3.Properties.ListBullet = c_bullet;
        paragraph3.Properties.ListBulletColor = new TextBulletColor(new OfficeColor(Color.Red));
        paragraph3.Text = "Paragraph 3";
        shape.TextArea.Paragraphs.Add(paragraph3);
    }
}
vb
Imports DevExpress.Docs
Imports DevExpress.Docs.Presentation
Imports DevExpress.Drawing
Imports System.Drawing

Namespace PresentationApiSample

    Public Class Program
        Public Shared Sub Main(__ As String())

            Dim presentation As Presentation = New Presentation()
            presentation.Slides.Clear()

            Dim slide As Slide = New Slide(SlideLayoutType.Blank)
            presentation.Slides.Add(slide)

            Dim shape As Shape = New Shape(ShapeType.Rectangle, 30, 30, 2000, 1000)
            slide.Shapes.Add(shape)

            ' Use a numbering bullet for a text paragraph
            Dim n_bullet As NumberingListBullet = New NumberingListBullet(NumberingListBulletFormat.WideBlackCircledNumber, 1)
            Dim paragraph1 As TextParagraph = New TextParagraph()
            paragraph1.Properties.ListBullet = n_bullet
            paragraph1.Text = "Paragraph 1"
            shape.TextArea.Paragraphs.Add(paragraph1)

            ' Use an image bullet for a text paragraph
            Dim stream As Stream = New FileStream("..\..\..\data\image.png", FileMode.Open, FileAccess.Read)
            Dim i_bullet As ImageListBullet = New ImageListBullet With {
                    .Image = New OfficeImage(DXImage.FromStream(stream))
                }
            Dim paragraph2 As TextParagraph = New TextParagraph()
            paragraph2.Properties.ListBullet = i_bullet
            paragraph2.Text = "Paragraph 2"
            shape.TextArea.Paragraphs.Add(paragraph2)

            ' Use a char bullet for a text paragraph
            Dim c_bullet As CharListBullet = New CharListBullet("•"c)
            Dim paragraph3 As TextParagraph = New TextParagraph()
            paragraph3.Properties.ListBullet = c_bullet
            paragraph3.Properties.ListBulletColor = New TextBulletColor(New OfficeColor(Color.Red))
            paragraph3.Text = "Paragraph 3"
            shape.TextArea.Paragraphs.Add(paragraph3)

        End Sub
    End Class
End Namespace

Specify Paragraph Indent Level

Use the textParagraph.Properties.ListIndentLevel property to set the paragraph’s nesting level in a hierarchical list. Valid values range from 0 to 8. To configure settings for specific levels, use the following properties:

TextArea.ParagraphPropertiesProperties that are applied to all paragraphs until level-specific properties are not set.TextArea.Level1ParagraphPropertiesProperties for paragraphs of Level 1.TextArea.Level2ParagraphPropertiesProperties for paragraphs of Level 2.TextArea.Level3ParagraphPropertiesProperties for paragraphs of Level 3.TextArea.Level4ParagraphPropertiesProperties for paragraphs of Level 4.TextArea.Level5ParagraphPropertiesProperties for paragraphs of Level 5.TextArea.Level6ParagraphPropertiesProperties for paragraphs of Level 6.TextArea.Level7ParagraphPropertiesProperties for paragraphs of Level 7.TextArea.Level8ParagraphPropertiesProperties for paragraphs of Level 8.TextArea.Level9ParagraphPropertiesProperties for paragraphs of Level 9.

The following example creates a hierarchical list with three levels and applies different settings to each level:

csharp
using DevExpress.Docs.Presentation;
using System.Drawing;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {

        Presentation presentation = new Presentation();

        presentation.Slides.Clear();

        Slide slide = new Slide(SlideLayoutType.Blank);
        presentation.Slides.Add(slide);

        Shape shape1 = new Shape(ShapeType.Rectangle);
        shape1.Outline = new LineStyle { Fill = new SolidFill(Color.White), Width = 8 };
        shape1.Fill = new SolidFill(Color.White);
        shape1.X = 1100;
        shape1.Y = 1100;
        shape1.Width = 3000;
        shape1.Height = 3000;

        shape1.TextArea.Paragraphs.Clear();

        shape1.TextArea.Paragraphs.Add(new TextParagraph { Text = "Level 1", Properties = new ParagraphProperties { ListIndentLevel = 0 } });
        shape1.TextArea.Level1ParagraphProperties = new ParagraphProperties { TextProperties = new TextProperties { Fill = new SolidFill(Color.Blue) } };

        shape1.TextArea.Paragraphs.Add(new TextParagraph { Text = "Level 2", Properties = new ParagraphProperties { ListIndentLevel = 1 } });
        shape1.TextArea.Level2ParagraphProperties = new ParagraphProperties { LeftIndent = 100, TextProperties = new TextProperties { Fill = new SolidFill(Color.Green) } };

        shape1.TextArea.Paragraphs.Add(new TextParagraph { Text = "Level 3", Properties = new ParagraphProperties { ListIndentLevel = 2 } });
        shape1.TextArea.Level3ParagraphProperties = new ParagraphProperties { LeftIndent = 200, TextProperties = new TextProperties { Fill = new SolidFill(Color.Red) } };

        slide.Shapes.Add(shape1);
    }
}
vb
Imports DevExpress.Docs.Presentation
Imports System.Drawing

Namespace PresentationApiSample

    Public Class Program
        Public Shared Sub Main(__ As String())

            Dim presentation As Presentation = New Presentation()

            presentation.Slides.Clear()

            Dim slide As Slide = New Slide(SlideLayoutType.Blank)
            presentation.Slides.Add(slide)

            Dim shape1 As Shape = New Shape(ShapeType.Rectangle)
            shape1.Outline = New LineStyle With {
                    .Fill = New SolidFill(Color.White),
                    .Width = 8
                }
            shape1.Fill = New SolidFill(Color.White)
            shape1.X = 1100
            shape1.Y = 1100
            shape1.Width = 3000
            shape1.Height = 3000

            shape1.TextArea.Paragraphs.Clear()

            shape1.TextArea.Paragraphs.Add(New TextParagraph With {
                    .Text = "Level 1",
                    .Properties = New ParagraphProperties With {
                        .ListIndentLevel = 0
                    }
                })
            shape1.TextArea.Level1ParagraphProperties = New ParagraphProperties With {
                    .TextProperties = New TextProperties With {
                        .Fill = New SolidFill(Color.Blue)
                    }
                }

            shape1.TextArea.Paragraphs.Add(New TextParagraph With {
                    .Text = "Level 2",
                    .Properties = New ParagraphProperties With {
                        .ListIndentLevel = 1
                    }
                })
            shape1.TextArea.Level2ParagraphProperties = New ParagraphProperties With {
                    .LeftIndent = 100,
                    .TextProperties = New TextProperties With {
                        .Fill = New SolidFill(Color.Green)
                    }
                }

            shape1.TextArea.Paragraphs.Add(New TextParagraph With {
                    .Text = "Level 3",
                    .Properties = New ParagraphProperties With {
                        .ListIndentLevel = 2
                    }
                })
            shape1.TextArea.Level3ParagraphProperties = New ParagraphProperties With {
                    .LeftIndent = 200,
                    .TextProperties = New TextProperties With {
                        .Fill = New SolidFill(Color.Red)
                    }
                }

            slide.Shapes.Add(shape1)
        End Sub
    End Class
End Namespace

Replace Text

Call the TextArea.ReplaceText method to replace text within the TextArea:

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...
        shape.TextArea.ReplaceText("dx-sample.com", "dx-test.org");
        shape.TextArea.ReplaceText(shape.TextArea.FindText("com"), "org");
        shape.TextArea.ReplaceText(new TextRange(10,3), "org");
        shape.TextArea.ReplaceText("dx-sample.com", "dx-test.org", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });
    }
}
vb
Imports DevExpress.Docs.Presentation

Namespace PresentationApiSample

    Public Class Program
        Public Shared Sub Main(__ As String())
            ' ...
            shape.TextArea.ReplaceText("dx-sample.com", "dx-test.org")
            shape.TextArea.ReplaceText(shape.TextArea.FindText("com"), "org")
            shape.TextArea.ReplaceText(New TextRange(10, 3), "org")
            shape.TextArea.ReplaceText("dx-sample.com", "dx-test.org", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })
        End Sub
    End Class
End Namespace

Find Text

Call the TextArea.FindText method to obtain all text ranges that contain the specified text:

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...
        IList<TextRange> textRanges = shape.TextArea.FindText("com");
        IList<TextRange> textRanges = shape.TextArea.FindText("com", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });
    }
}
vb
Imports DevExpress.Docs.Presentation

Namespace PresentationApiSample
    Public Class Program
        Public Shared Sub Main(__ As String())
            ' ...
            Dim textRanges = shape.TextArea.FindText("com")
            Dim textRanges As IList(Of TextRange) = shape.TextArea.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })
        End Sub
    End Class
End Namespace

Remove Text

Call the TextArea.RemoveText method to remove the specified text from the TextArea:

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...
        shape.TextArea.RemoveText(shape.TextArea.FindText("com"));
    }
}
vb
Imports DevExpress.Docs.Presentation

Namespace PresentationApiSample

    Public Class Program
        Public Shared Sub Main(__ As String())
            ' ...
            shape.TextArea.RemoveText(shape.TextArea.FindText("com"))

        End Sub
    End Class
End Namespace

Apply Custom Formatting to a Specified Text Range

Call the TextArea.ModifyTextProperties method to apply text properties to a specified text range. For example, you can highlight text (change its background color).

The following code snippet finds all occurrences of the “com” substring in a shape’s text area and changes their font color to red:

csharp
using DevExpress.Docs.Presentation;
using System.Drawing;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {

        Presentation presentation = new Presentation(File.ReadAllBytes(@"..\..\..\data\Presentation.pptx"));

        Shape shape = presentation.Slides[0].Shapes[0] as Shape;

        IList<TextRange> textRanges = shape.TextArea.FindText("com", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });
        foreach (var item in textRanges) {
            shape.TextArea.ModifyTextProperties(item, new TextProperties { Fill = new SolidFill(Color.Red) });
        }
    }
}
vb
Imports DevExpress.Docs.Presentation
Imports System.Drawing
Imports System.IO
Imports System.Collections.Generic

Namespace PresentationApiSample
    Public Class Program
        Public Shared Sub Main(__ As String())

            Dim presentation As New Presentation(File.ReadAllBytes("..\..\..\data\Presentation.pptx"))

            Dim shape As Shape = TryCast(presentation.Slides(0).Shapes(0), Shape)

            Dim textRanges As IList(Of TextRange) = shape.TextArea.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })

            For Each item As TextRange In textRanges
                shape.TextArea.ModifyTextProperties(item, New TextProperties With {
                    .Fill = New SolidFill(Color.Red)
                })
            Next
        End Sub
    End Class
End Namespace

Extract Text

For more information on how to extract text from shapes, refer to the following help topic: Extract Presentation Content.