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

PositionHandlerWalker

1 Answer 37 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Terje
Top achievements
Rank 1
Terje asked on 12 Feb 2013, 04:05 PM
Hello Telerik

In my appication I have a series of vertically stacked RichTextBoxes. What I would like to do is to detect if the Caret is on the first or last line in the document, so that I can move the the focus and set the Caret in the previous or next RTB, if the user ties to "walk out of a RTB". Hope this makes sense.

When debugging I noticed that in the RichTextBox.Document.CaretPosition there was a positionHandlerWalker.CanMoveUp and CanMoveDown property which kind of sounded what if am after, but it doesn't seem that the positionHandlerWalker property is available.

Hope you can help

/Terje

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 18 Feb 2013, 04:50 PM
Hi Terje,

What you can do is handle the PreviewEditorKeyDown event of your RadRichTextBox instances and check whether the caret should leave the rich text box. There are methods MoveDown() and MoveUp() of the caret which return a bool value showing whether the methods can be executed. You can handle the cases when navigating up/down/left/right is invoked and check whether they can be executed. 

For example, this is how you should go about handling pressing the down arrow:
void editro1_PreviewEditorKeyDown(object sender, Telerik.Windows.Documents.PreviewEditorKeyEventArgs e)
{
    if (e.Key == Key.Down)
    {
        if (!editor1.Document.CaretPosition.MoveDown())
        {
            editor2.Focus();
        }
        else
        {
            e.SuppressDefaultAction = true;
        }
    }
}

I hope this information is helpful! Let us know if there is anything else we can assist you with.
 
Regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Terje
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or