Cursor/Caretposition while in Readonly

2 posts, 0 answers
  1. JoRoSch
    JoRoSch avatar
    8 posts
    Member since:
    Dec 2011

    Posted 09 Dec 2013 Link to this post

    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
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 11 Dec 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top