Add Method
- Namespace
TXTextControl
- Package
TXTextControl.asTextControl. WinForms. SDK TXTextControl.from the private NuGet feed or Text Control Offline Packagesdll
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);Public Function Add(subTextPart As SubTextPart) As SubTextPartCollection.AddResultParameters
| Parameter | Description |
|---|---|
| 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}");
}textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim customer As New SubTextPart("CustomerName", 10) With {
.HighlightColor = System.Drawing.Color.LightGoldenrodYellow,
.HighlightMode = HighlightMode.Always
}
Dim result As SubTextPartCollection.AddResult = textControl.SubTextParts.Add(customer)
If result <> SubTextPartCollection.AddResult.Successful Then
Throw New InvalidOperationException($"The region could not be added: {result}")
End If