我的WPF程序中有RichTExtBox。想象一下,我有2个TextPointers,表示RTB某些部分的第一个和最后一个。如果输入的文本在这两个指针之间,我怎么知道呢?
//i have the values of these 3 pointer.imagine they are filled
private bool isBetween(TextPointer first,TextPointer Last,TextPointer Current){
//i don't know how to write this function
}
上面的代码First
中的和Last
表示该区域!我希望这个函数告诉我这两个TextPointers之间是否Current
?
答案 0 :(得分:0)
尝试:
private bool isBetween(TextPointer first,TextPointer last,TextPointer current)
{
bool isAfterFirst = first.GetOffsetToPosition(current) >= 0;
bool isBeforeLast = last.GetOffsetToPosition(current) <= 0;
return isAfterFirst && isBeforeLast;
}
添加您认为合适的所有空检查......
答案 1 :(得分:0)
您可以从2 TextRange
创建TextPointers
并使用方法Contains
。这很容易:
private bool isBetween(TextPointer first,TextPointer last,TextPointer current){
return new TextRange(first, last).Contains(current);
}