How to deleted two characters to the left of the cursor in a RichTextBox in Silverlight

I need help with code for the click event of a Button1 that will delete two characters to the left of the current cursor position in a richTextBox1 on a Silverlight 4 Page.  

Therefore if the following the text in richTextBox1 before clicking Button1 (with the cursor currently being just after the full stop)

This is a simple sentencee.

After clicking Button1 it should look like

This is a simple sentence

Please note that clicking Button1 has deleted full stop and the extra e at the end of the word "sentence"

Thank you for your help in anticipation.

LVL 1
FaheemAhmadGulAsked:
Who is Participating?
 
saraganiCommented:
Hi, sorry for the delay, I was kinda busy. Here is a solution:

            TextSelection textRange = richTextBox1.Selection;
            TextPointer tp = textRange.Start;
            TextPointer startPos = tp.GetPositionAtOffset(-2, LogicalDirection.Forward);
            textRange.Select(startPos, tp);
            richTextBox1.Selection.Text = "";


The idea of this solution is setting the selection from the start of the cursor 2 chars backwards and then setting the selected text to be an empty string.
0
 
FaheemAhmadGulAuthor Commented:
Excellent!
Many thanks. Regards
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.