WPF RichTexBox - How to move the cursor one character to the left programmatically in WPF RichTextBox

I would like to move the cursor one space to the left in a WPF RichTextBox through code.
So if I have sentence like the following:

This is an apple .
And now if my cursor is currently just after the full stop in the above sentence and I call my function twice (that is move the cursor two spaces to the left, the cursor will then position itself between e (of the apple) and the fullstop.

Thank you for your help.
LVL 1
FaheemAhmadGulAsked:
Who is Participating?
 
louisfrConnect With a Mentor Commented:
Set the CaretPosition to the new position. You can create it with the GetPositionAtOffset method:
rtb.CaretPosition = rtb.CaretPosition.GetPositionAtOffset(-2)

Open in new window

0
 
FaheemAhmadGulAuthor Commented:
Many thanks. Greatly appreciated!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.