Kae Vee

Kae Vee

  • NA
  • 3
  • 3.8k

How to get the current offset position in Rich text box

Nov 12 2018 5:01 AM
While am going edit mode in Richtext box by double click, the caret position goes either to start or to the end of the text. But in normal text box wherever you double click, the cusrsor in the correct position.
How to change the caret position based on mouse clicking position? here i provided the code what i have tried.
I want to get excel like behavior.
TextPointer tp = richtextbox.CaretPosition;
tp = tp.GetNextInsertionPosition(LogicalDirection.Forward);
richtextbox.Selection.Select(richtextbox.CaretPosition, tp);
 
TextPointer start = richtextbox.Document.ContentStart;
TextPointer caret = richtextbox.CaretPosition;
TextRange range = new TextRange(start, caret);
int indexInText = range.Text.Length;
I have double clicked near "3" in "12345" highlighted as yellow in snapshot. But the caret blinks at the start position.