This is a migrated thread and some comments may be shown as answers.

Cursor/Caretposition while in Readonly

1 Answer 146 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
JoRoSch
Top achievements
Rank 1
JoRoSch asked on 09 Dec 2013, 11:50 AM
Hello,
using a RadRichTextBox I am facing the following:
Document is not in readonly mode -> Cursor is visible, can be moved via mouse and keyboard = > okay!
Document is in readonly mode -> Cursor is not visible, but can be moved via mouse and keyboard and shows up on a not expected postion when the document comes back to an editable state again. What can I do against this behaviour?

Another question I have: Is it possible to keep an selection made while in an editable state, but do not permit selection while in "readonly" (setting "isSelectionEnabled" to false)?

Thanks in advance

Jo

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 11 Dec 2013, 03:46 PM
Hello Jo,

Thank you for contacting us!

The DocumentSelection class allows you to preserve the selection even if the RadRichTextBox in your application does not currently allow selection. Further, setting the IsSelectionEnabled property to false will prevent the caret from changing its position. That said, here is how I suggest you implement your requirements:
if (this.radRichTextBox.IsSelectionEnabled)
{
    selection = new DocumentSelection(this.radRichTextBox.Document);
    foreach (var range in this.radRichTextBox.Document.Selection.Ranges)
    {
        selection.AddSelectionStart(range.StartPosition);
        selection.AddSelectionEnd(range.EndPosition);
    }
 
    this.radRichTextBox.IsReadOnly = !this.radRichTextBox.IsReadOnly;
    this.radRichTextBox.IsSelectionEnabled = !this.radRichTextBox.IsSelectionEnabled;
 
}
else
{
    this.radRichTextBox.IsReadOnly = !this.radRichTextBox.IsReadOnly;
    this.radRichTextBox.IsSelectionEnabled = !this.radRichTextBox.IsSelectionEnabled;
 
    foreach (var range in selection.Ranges)
    {
        this.radRichTextBox.Document.Selection.AddSelectionStart(range.StartPosition);
        this.radRichTextBox.Document.Selection.AddSelectionEnd(range.EndPosition);
    }
}

I hope this helps!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
JoRoSch
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or