officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-dot-beginupdatecharacters-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-int32-x29.md
Starts modifying properties of the specified number of characters starting at the specified document position.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
CharacterProperties BeginUpdateCharacters(
DocumentPosition start,
int length
)
Function BeginUpdateCharacters(
start As DocumentPosition,
length As Integer
) As CharacterProperties
| Name | Type | Description |
|---|---|---|
| start | DocumentPosition |
A DocumentPosition, specifying the starting document position.
| | length | Int32 |
An integer specifying the number of positions to which formatting is applied.
|
| Type | Description |
|---|---|
| CharacterProperties |
A CharacterProperties object representing the character formatting of the specified range.
|
Use the SubDocument.BeginUpdateCharacters and the SubDocument.EndUpdateCharacters paired methods to modify character formatting, such as the CharacterPropertiesBase.FontName, CharacterPropertiesBase.FontSize, CharacterPropertiesBase.Bold, CharacterPropertiesBase.ForeColor etc.
To accomplish this, call the SubDocument.BeginUpdateCharacters method for the specified range, use the returned CharacterProperties interface to modify the required properties and call the SubDocument.EndUpdateCharacters method to finalize the modification.
Note
Make sure that the SubDocument.BeginUpdateCharacters method always has its corresponding SubDocument.EndUpdateCharacters method to ensure proper operation of the control.
The following code snippet changes the font and the color of the selected text.
document.BeginUpdate();
document.AppendText("Normal\nFormatted\nNormal");
document.EndUpdate();
// The target range is the second paragraph
DocumentRange range = document.Paragraphs[1].Range;
// Create and customize an object
// that sets character formatting for the selected range
CharacterProperties cp = document.BeginUpdateCharacters(range);
cp.FontName = "Comic Sans MS";
cp.FontSize = 18;
cp.ForeColor = Color.Blue;
cp.BackColor = Color.Snow;
cp.Underline = UnderlineType.DoubleWave;
cp.UnderlineColor = Color.Red;
// Finalize modifications
// with this method call
document.EndUpdateCharacters(cp);
document.BeginUpdate()
document.AppendText("Normal" & vbLf & "Formatted" & vbLf & "Normal")
document.EndUpdate()
' The target range is the second paragraph
Dim range As DocumentRange = document.Paragraphs(1).Range
' Create and customize an object
' that sets character formatting for the selected range
Dim cp As CharacterProperties = document.BeginUpdateCharacters(range)
cp.FontName = "Comic Sans MS"
cp.FontSize = 18
cp.ForeColor = Color.Blue
cp.BackColor = Color.Snow
cp.Underline = UnderlineType.DoubleWave
cp.UnderlineColor = Color.Red
' Finalize modifications
' with this method call
document.EndUpdateCharacters(cp)
The following code snippets (auto-collected from DevExpress Examples) contain references to the BeginUpdateCharacters(DocumentPosition, Int32) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Shapes.cs#L64
textBoxDocument.AppendText("TextBox Text");
CharacterProperties cp = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7);
cp.ForeColor = System.Drawing.Color.Orange;
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/ShapesActions.cs#L75
textBoxDocument.AppendText("TextBox Text");
CharacterProperties cp = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7);
cp.ForeColor = System.Drawing.Color.Orange;
word-document-api-examples/CS/CodeExamples/ShapesActions.cs#L123
// Format the boxed text.
CharacterProperties cp = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7);
cp.ForeColor = System.Drawing.Color.Orange;
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Shapes.vb#L59
textBoxDocument.AppendText("TextBox Text")
Dim cp As DevExpress.XtraRichEdit.API.Native.CharacterProperties = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7)
cp.ForeColor = System.Drawing.Color.Orange
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/ShapesActions.vb#L66
textBoxDocument.AppendText("TextBox Text")
Dim cp As CharacterProperties = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7)
cp.ForeColor = System.Drawing.Color.Orange
word-document-api-examples/VB/CodeExamples/ShapesActions.vb#L100
' Format the boxed text.
Dim cp As DevExpress.XtraRichEdit.API.Native.CharacterProperties = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7)
cp.ForeColor = System.Drawing.Color.Orange
See Also