Reputation: 135
I am writing a application using WPF C# Windows application.i want to navigate word by word in that richtextbox content.how to i done it. i already tried to move current word to next word navigation.its work. i am using the below code.
TextPointer starting = txtAppendValue.Document.ContentStart;
startval = txtAppendValue.CaretPosition;
text = startval.GetTextInRun(LogicalDirection.Backward);
newWord = txtAppendValue.CaretPosition.GetNextInsertionPosition(LogicalDirection.Forward);
if (newWord != null)
{
txtAppendValue.CaretPosition = newWord;
txtptrCaret = txtAppendValue.CaretPosition;
NextStringvalue = txtptrCaret.GetTextInRun(LogicalDirection.Forward);
{
txtptrCaret = txtAppendValue.CaretPosition;
range1 = new TextRange(starting, txtptrCaret);
indexInText = range1.Text.Length;
}}
this below line newword text pointer to give a next word to end of the content.
newWord = txtAppendValue.CaretPosition.GetNextInsertionPosition(LogicalDirection.Forward);
So now how to i get an previous word and all other words text pointer?
Note: i already get the previous words using content start and caretposition.but it gives like strings. i want textpointer value to move each previous word.
Regards Arjun
Upvotes: 0
Views: 764
Reputation: 354566
You could use the MoveRightByWord and MoveLeftByWord commands for this:
EditingCommands.MoveLeftByWord.Execute(null, richTextBox);
According to the documentation, both commands are supported by RichTextBox.
Note, though, that when the input caret is within a word, this command moves it to the start of that word, not to the start of the previous word.
Upvotes: 0