Hi,
Let me describe my use case in these following steps:
- created a RadRichTextEditor
- set the RadRichTextEditor text to "This is a sample"
- set the cursor before the letter "s" from the word "sample"
- created a readonly span and set the fore color to Yellow
- inserted the readonly span "Inserted text" before the word "sample"
Please see the output from the attachment: InsertTextOnCurrentCaretPosition_UI_1.0.PNG
Code below, is the method of insertion of readonly span
public void InsertTextOnCurrentCaretPosition()
{
// Creating and setting span
Span readOnlyContent = new Span("Inserted text");
readOnlyContent.ForeColor = Color.FromRgb(255, 255, 0); // Yellow
// Get the position of the current caret
DocumentPosition caretPosition = new DocumentPosition(radRichTextEditor.Document.CaretPosition);
caretPosition.AnchorToCurrentBoxIndex();
// Insert the span
radRichTextEditor.Document.Selection.Clear();
radRichTextEditor.InsertInline(readOnlyContent);
// Get the position of the current caret after inserting the span
caretPosition.RestorePositionFromBoxIndex();
DocumentPosition endCitation = radRichTextEditor.Document.CaretPosition;
// Select the span by caret positions and insert as read only
radRichTextEditor.Document.Selection.AddSelectionStart(caretPosition);
radRichTextEditor.Document.Selection.AddSelectionEnd(endCitation);
radRichTextEditor.InsertReadOnlyRange();
radRichTextEditor.Focus();
}
After the insertion of the readonly span, I key-in 3 letter "a" and expected the fore color would be Black, but it seems it retained the color (Yellow) of the readonly span. As you can see on this attachment: InsertTextOnCurrentCaretPosition_UI_1.1.PNG
Is there a way to set/reset the fore color to Black after the readonly span? so that the key-in values would be in color Black
Code below, I tried setting the fore color to Black right after the InsertReadOnlyRange, but it changes the fore color of the 2nd word "text" of the readonly span as you can see on this attachment: InsertTextOnCurrentCaretPosition_UI_2.0.PNG
public void InsertTextOnCurrentCaretPosition()
{
// Creating and setting span
Span readOnlyContent = new Span("Inserted text");
readOnlyContent.ForeColor = Color.FromRgb(255, 255, 0); // Yellow
// Get the position of the current caret
DocumentPosition caretPosition = new DocumentPosition(radRichTextEditor.Document.CaretPosition);
caretPosition.AnchorToCurrentBoxIndex();
// Insert the span
radRichTextEditor.Document.Selection.Clear();
radRichTextEditor.InsertInline(readOnlyContent);
// Get the position of the current caret after inserting the span
caretPosition.RestorePositionFromBoxIndex();
DocumentPosition endCitation = radRichTextEditor.Document.CaretPosition;
// Select the span by caret positions and insert as read only
radRichTextEditor.Document.Selection.AddSelectionStart(caretPosition);
radRichTextEditor.Document.Selection.AddSelectionEnd(endCitation);
radRichTextEditor.InsertReadOnlyRange();
// Change the color of the editor back to black
radRichTextEditor.Document.Selection.Clear();
radRichTextEditor.ChangeTextForeColor(Color.FromRgb(0, 0, 0)); // Black
radRichTextEditor.DocumentInheritsDefaultStyleSettings = true;
radRichTextEditor.Focus();
}