The original issue was that when the application was alt tabbed away from and then back to after they had copied text from somewhere else to paste where their cursor is in the radrichtextbox, the cursor moved. The solution to this was to create 2 methods in the control that we have wrapped around the radrichtextbox, the first one is called at the beginning of the lost focus and the second one is 2 lines of code later after the text is pulled into the data context. The cursor position works fine but it now loses selection when right clicking because right click fires lostfocus which resets the cursor position. Here is the attempt to re-select the selection (assuming 1 text selection area). The storing works but the re-setting blows up.
private PointF _position;
private DocumentPosition _start;
private DocumentPosition _end;
public void StoreCaretPosition()
{
_position = rtArea.Document.CaretPosition.Location;
if (rtArea.Document.Selection.Ranges.First != null)
{
_start = new DocumentPosition(rtArea.Document.Selection.Ranges.First.StartPosition);
_end = new DocumentPosition(rtArea.Document.Selection.Ranges.First.EndPosition);
}
}
public void RestoreCaretPosition()
{
rtArea.Document.CaretPosition.SetPosition(_position);
rtArea.Document.Selection.AddSelectionStart(_start);
rtArea.Document.Selection.AddSelectionEnd(_end);
}
The error we are getting is after adding the end selection it blows up on the method’s end curly bracket with the error ‘inline does not belong to this document.’