TX Text Control .NET for Windows Forms

Add Method

Method|Introduced in 23.0
Namespace
TXTextControl
Package
TXTextControl.TextControl.WinForms.SDK as TXTextControl.dll from the private NuGet feed or Text Control Offline Packages

Description

Adds a new subtextpart to the document. Its position is defined through the SubTextPart.Start and SubTextPart.Length properties. If the subtextpart's length is zero, the current text selection is used to define the position.

Syntax

public SubTextPartCollection.AddResult Add(SubTextPart subTextPart);

Parameters

ParameterDescription
subTextPart

Specifies the subtextpart to add.

Return Value

The return value specifies whether the new textpart has successfully been inserted. It can be one of the SubTextPartCollection.AddResult values.

Examples

The following example turns the selected customer name into a highlighted SubTextPart and checks the insertion result.

textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);

SubTextPart customer = new("CustomerName", 10)
{
    HighlightColor = System.Drawing.Color.LightGoldenrodYellow,
    HighlightMode = HighlightMode.Always
};

SubTextPartCollection.AddResult result = textControl.SubTextParts.Add(customer);
if (result != SubTextPartCollection.AddResult.Successful)
{
    throw new InvalidOperationException($"The region could not be added: {result}");
}