RichTextBox
中的文本,用户可以向前或向后选择文本。如何以编程方式确定选择的方向? (LogicalDirection
和End
中的Start
并不表示这一点)
答案 0 :(得分:2)
您可以将CaretPosition
与当前Selection
进行比较,以确定从哪个方向选择文本:
TextPointer caretPos = richTextBox.CaretPosition;
TextPointer selectStart = richTextBox.Selection.Start;
TextPointer selectEnd = richTextBox.Selection.End;
if(caretPos.CompareTo(selectStart) == 0)
{
//The text was selected from right to left.
}
else if(caretPos.CompareTo(selectEnd) == 0)
{
//The text was selected from left to right.
}