This is a migrated thread and some comments may be shown as answers.

Is caret at line end / start

0 Answers 71 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 07 May 2012, 04:42 PM

I sent a support ticket to the telerik admins asking if there were any API methods to determine if the caret is at the start and end of a line.
They responded with a solution so I thought I should share it with everyone else.

Is Caret at Line Start

public static bool IsCaretAtLineStart(RadDocument document)
{
    DocumentPosition endLinePosition = new DocumentPosition(document.CaretPosition);
    endLinePosition.MoveToCurrentLineStart();
 
    if (document.CaretPosition == endLinePosition)
    {
        return true;
    }
 
    return false;
}


Is Caret at Line End

public static bool IsCaretAtLineEnd(RadDocument document)
{
    DocumentPosition endLinePosition = new DocumentPosition(document.CaretPosition);
    endLinePosition.MoveToCurrentLineEnd();
 
    if (document.CaretPosition == endLinePosition)
    {
        return true;
    }
 
    return false;
}


I hope this helps you as it did myself.

Thanks,

Rob

No answers yet. Maybe you can help?

Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Share this question
or